我是从
实施自定义提醒视图http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
但我希望在设备方向更改时使自定义警报视图旋转。当我第一次在iphone模拟器的纵向方向上运行该应用程序时,自定义警报视图方向是横向的,但是当我将设备旋转到横向左侧时,自定义警报视图方向是横向的。在以多种方式旋转设备后,我发现自定义警报方向跟随主页按钮位置..
我实施了以下几种方法:
-(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");
}
但没有人被称为...... 任何人都可以帮我解决为什么自定义警报视图不像我想要的那样旋转吗?
更新: 我实现了像这样的viewWillAppear方法
-(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(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);
}
}
但条件刚刚在第一次启动应用程序时完成,之后,即使我多次旋转设备也没有任何条件和声明
答案 0 :(得分:1)
已经完成...... 见About the orientation of iPhone 找到答案:)
答案 1 :(得分:0)
UIView无法接受UIViewController的委托消息。因此,您应该注册为观察员才能收到UIDeviceOrientationDidChangeNotification通知。