Iphone 防止在旋转过程中更改接口
我想支持所有方向,但肖像。我想做一些简单的事情,但我从来没有找不到解决办法 我的界面上有6个大按钮。加上2个额外的小按钮 当方向改变时,我想将所有8个按钮保持在同一个中心/位置,我只想旋转6个大按钮,使它们朝向正确的方向 我试着设置Iphone 防止在旋转过程中更改接口,iphone,ios,objective-c,orientation,Iphone,Ios,Objective C,Orientation,我想支持所有方向,但肖像。我想做一些简单的事情,但我从来没有找不到解决办法 我的界面上有6个大按钮。加上2个额外的小按钮 当方向改变时,我想将所有8个按钮保持在同一个中心/位置,我只想旋转6个大按钮,使它们朝向正确的方向 我试着设置 - (BOOL)shouldAutorotate { return NO; } 给自己发一个通知,但是我必须处理旧的方向和新的方向,以便旋转到正确的位置。还有其他可能性吗?另外,由于通知是在方向更改后发送的(UIDeviceOrientationIDCha
- (BOOL)shouldAutorotate
{
return NO;
}
给自己发一个通知,但是我必须处理旧的方向和新的方向,以便旋转到正确的位置。还有其他可能性吗?另外,由于通知是在方向更改后发送的(UIDeviceOrientationIDChangeNotification),因此我无法获得上一个方向。这是我在视图旋转时用于旋转按钮图像的方法:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDeviceOrientationDidChangeNot:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)handleDeviceOrientationDidChangeNot:(NSNotification *)not {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CGFloat angle = 0.0;
switch (orientation) {
case UIDeviceOrientationPortrait:
angle = 0.0;
break;
case UIDeviceOrientationLandscapeLeft:
angle = M_PI/2;
break;
case UIDeviceOrientationPortraitUpsideDown:
angle = M_PI;
break;
case UIDeviceOrientationLandscapeRight:
angle = -M_PI/2;
break;
default:
return;
break;
}
[UIView animateWithDuration:0.35 animations:^{
self.someButton.imageView.transform = CGAffineTransformMakeRotation(angle);
} completion:^(BOOL finished) {
//
}];
}
您使用的是自动调整大小还是约束?它可以帮助您在方向改变时自动调整组件。我正在使用AutoSizing这正是我所做的!但是,如果您在一次移动中从UIDeviceOrientation和SCAPE向右移动到UIDeviceOrientation和SCAPE向左移动,会发生什么情况,它会将-M_PI/2旋转到0吗?(-M_PI/2+M_PI/2=0)CGAffineTransformMakeRotation是否使用最终角度或位移?不确定,但根据我的记忆,它对我来说很好。你试过了吗?