iphone – 只有一个视图在xcode中自动旋转?
发布时间:2020-12-14 17:36:58 所属栏目:百科 来源:网络整理
导读:好的,所以我目前有3个视图,我只需要其中一个自动旋转到任何方向,而其余的保持纵向.现在我的设置是一个splashviewcontroller淡入视图A,内部视图A是一个切换到视图B的按钮.我想要的是视图B能够旋转到任何方向. 当我在splashviewcontroller中为shouldautorotate
|
好的,所以我目前有3个视图,我只需要其中一个自动旋转到任何方向,而其余的保持纵向.现在我的设置是一个splashviewcontroller淡入视图A,内部视图A是一个切换到视图B的按钮.我想要的是视图B能够旋转到任何方向.
当我在splashviewcontroller中为shouldautorotatetointerfaceorientation返回YES时,每个视图都会旋转,因为这是父视图.当我仅在splashview中返回肖像时,即使其他视图返回YES,也不会旋转.有没有办法让视图B旋转?如果你能提供代码,我愿意手动完成.谢谢 解决方法
你可以手动管理任何所需的UIView对象的旋转,如下所示:
编辑: 在init或viewDidLoad中 - (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotate) name:UIDeviceOrientationDidChangeNotification object:nil];
[super viewDidLoad];
}
#define degreesToRadian(x) (M_PI * (x) / 180.0)
-(void)rotate{
self.view.bounds = CGRectMake(0,0);
if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortrait){
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(0));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform,0.0,0.0);
self.view.bounds = CGRectMake(self.view.bounds.origin.x,self.view.bounds.origin.y,320,480);
[self.view setTransform:landscapeTransform];
} else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortraitUpsideDown){
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(180));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform,480);
[self.view setTransform:landscapeTransform];
} else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight){
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform,0.0);
self.view.bounds = CGRectMake(self.view.bounds.origin.x,480,320);
[self.view setTransform:landscapeTransform];
}else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft){
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform,0.0);
self.view.bounds = CGRectMake(self.view.bounds.origin.x,320);
[self.view setTransform:landscapeTransform];
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
