开发者

Is there a way to skip animating a rotation from shouldAutorotateToInterfaceOrientation?

开发者 https://www.devze.com 2023-01-07 13:20 出处:网络
I would like to allow the orientation to rotate as per the shouldAutorotateToInterfaceOrientation call to my view controller.However, I\'d like it to do so immedia开发者_运维知识库tely and skip the ro

I would like to allow the orientation to rotate as per the shouldAutorotateToInterfaceOrientation call to my view controller. However, I'd like it to do so immedia开发者_运维知识库tely and skip the rotating animation (the one that results in the corners showing the black rotating animation while the entire view rotates.

Does anyone know if there is a way to specify that you want it to occur immediately (without animating)?


In order to do what you want, you must manually rotate (and resize) your view. There is no property you can change to easily do what you wish. Below is the code to register for device rotation events.

 - (void)viewDidLoad {
 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
             name:UIDeviceOrientationDidChangeNotification object:nil]; 
//Whenever the device orientation changes, orientationChanged will be called

}


- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
//Based upon which orientation the device is in, update your View rotations.
//A simple view.transform = CGAffineTransformMakeRotation(whatever); will work well.
}

I believe you should remove the shouldAutoRotateToInterfaceOrientation: function altogether. You should also call [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; when your view unloads.


It's not required to manually rotate. There is a way to just disable rotation animations.

Here's the answer how to do it: https://stackoverflow.com/a/6589568/894671

0

精彩评论

暂无评论...
验证码 换一张
取 消