自定义警报视图不会随着设备旋转而旋转
实现了自定义警报视图
我从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);
}
}
但条件只是在第一次启动应用程序时满足,之后,即使我多次旋转设备,也没有条件和语句被调用
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(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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完成了...
请参阅关于 iPhone 的方向
寻找答案:)
It's DONE...
see About the orientation of iPhone
to find the answer :)
UIView无法接受UIViewController的委托消息。因此,您应该注册为观察者以接收 UIDeviceOrientationDidChangeNotification 通知。
UIView cannot accept the delegate messages of UIViewController. So you should register as an observer to receive the UIDeviceOrientationDidChangeNotification notification.