开发者

custom alert view does not rotate toward device rotation

i was implement a custom alert view from

http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html

but i want to make that custom alert view rotate when the device orientation change. when i run that application at the first time in portrait orientation of iphone simulator, the custom alert view orientation is landscape, but when i rotate the device into landscape left, the custom alert view orientation is landscape. After rotating the device in many ways, i found that the custom alert orientation is follow suit the home button position..

i was implement this several methods :

-(void) willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"kkksksksk");    

}

-(void) willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 NSLog(@"aaa"); 

}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 NSLog(@"bbb");

}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 NSLog(@"bbb");

}

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@"ccc");

}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
NSLog(@"shouldAutorotateToInterfaceOrientation");

}

but no one was called... Can anyone help me in working out why the custom alert view isn't rotating like i want ?

UPDATE : i was implement the viewWillAppear method like this

-(void)viewWillAppear:(BOOL)animated {

UIInterfaceOrientation toOrientation = self.interfaceOrientation;
if(toOrientation == UIInterfaceOrientationPortrait){
    CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 180 / 180.0f);
    NSLog(@"vwa : portrait upside down");

    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];

    //[self.view setTransform:affine];
    self.view.center = CGPointMake(160, 240);
    NSLog(@"affine : %f", affine);

}else if(toOrientation == UIInterfaceOrientationPortraitUpsideDown){
    CGAffineTransform affine = CGAffineTransformMakeRotation (0.0);

    NSLog(@"vwa : Portrait ");

    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];
    self.view.center = CGPointMake(160, 240);
    NSLog(@"affine : %f", affine);
}else if(开发者_JAVA技巧toOrientation == UIInterfaceOrientationLandscapeLeft){
    CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 270 / 180.0f);

    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];
    self.view.center = CGPointMake(160, 240);

    NSLog(@"vwa : landscpae left");

    NSLog(@"affine : %f", affine);
}else{
    CGAffineTransform affine = CGAffineTransformMakeRotation ( M_PI * 90 / 180.0f);
    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];
    self.view.center = CGPointMake(160, 240);

    NSLog(@"vwa : landscape right");
    NSLog(@"affine : %f", affine);
}

}

but the condition just fulfilled at the first time launching the app, after that, there're no condition and statement called even i rotate the device many times


It's DONE... see About the orientation of iPhone to find the answer :)


UIView cannot accept the delegate messages of UIViewController. So you should register as an observer to receive the UIDeviceOrientationDidChangeNotification notification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜