【发布时间】:2010-11-26 03:19:45
【问题描述】:
我从
实现了一个自定义警报视图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);
}
}
但是在第一次启动应用程序时条件刚刚满足,之后,即使我多次旋转设备,也没有调用条件和语句
【问题讨论】:
-
你应该格式化你的代码...
-
“你应该格式化你的代码”是什么意思?对不起,我不明白
-
本网站支持代码格式,您应该使用这种格式。您可以在底部视图中验证编辑结果。