[英]How to trigger a function when the iPhone is rotated 90 degrees?
如何检测iPhone的旋转大约90度? 此外,我不需要/希望屏幕本身旋转。 我只是想在手机旋转时调用一个功能。 谢谢!
您的视图控制器将被发送:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
实现它以在手机旋转时执行某些操作
轮换完成后,您将获得:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
这是在文档中(请参阅处理视图旋转)
旋转设备时,视图控制器会收到带有旧方向的didRotateFromInterfaceOrientation:消息。 您可以检查interfaceOrientation属性以查看当前轮换,并相应地执行某些操作。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
您需要捕获ViewController轮换之前发送的事件。 即:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
和后轮换
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
您应该首先实现实例方法“shouldAutorotateToInterfaceOrientation”并返回YES。 然后将调用这两个方法。
方法名称是正确的......但它们永远不会被调用。 会导致什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.