[英]Turn off default rotate animation in iOS
When I rotate my iDevice form portrait to landscape, the screen rotates fine, but I'm seeing black borders moving with it, so it looks more 'real'. 当我将iDevice表单肖像旋转为横向时,屏幕旋转良好,但是我看到黑色边框随之移动,因此看起来更“真实”。 I find it embarrassing to see in iOS 7 and many apps have thrashed this behaviour (like Instagram).
我发现在iOS 7中看到它很尴尬,许多应用程序都破坏了这种行为(例如Instagram)。
What I want to do is hide those black borders that look totally unnecessary when rotating a device. 我想做的是隐藏那些在旋转设备时完全不需要的黑色边框。 How do I disable this standard animation?
如何禁用此标准动画?
In the parent view controller viewdidload method add this: 在父视图控制器的viewdidload方法中添加以下内容:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
Then add this method 然后添加此方法
- (void) didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIInterfaceOrientationIsLandscape(orientation) && !self.modalViewController) {
[self presentModalViewController:carouselView animated:YES];
[Globals sharedGlobals].startedAtLandscape = YES;
}
if (UIInterfaceOrientationIsPortrait(orientation) && self.modalViewController) {
[self dismissModalViewControllerAnimated:YES];
[Globals sharedGlobals].startedAtLandscape = NO;
}
}
Then to prevent animation: 然后防止动画:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return NO;
}
return YES;
}
I found the best solution is turn animation off before rotation, and turn it back after rotation. 我发现最好的解决方案是在旋转之前关闭动画,然后在旋转之后再将其关闭。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
...
[UIView setAnimationsEnabled:NO];
}
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
...
[UIView setAnimationsEnabled:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.