自定义警报视图不会随着设备旋转而旋转

发布于 2024-10-04 07:31:06 字数 3170 浏览 1 评论 0原文

实现了自定义警报视图

我从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

八巷 2024-10-11 07:31:06

完成了...
请参阅关于 iPhone 的方向
寻找答案:)

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

忘羡 2024-10-11 07:31:06

UIView无法接受UIViewController的委托消息。因此,您应该注册为观察者以接收 UIDeviceOrientationDidChangeNotification 通知。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文