【问题标题】:willAnimateRotationToInterfaceOrientation is or is not called on various deviceswillAnimateRotationToInterfaceOrientation 是否在各种设备上调用
【发布时间】:2013-10-21 20:56:57
【问题描述】:

我对(我想)方向回调有疑问。 我的应用程序以横向模式运行,但有两种模式可用(左/右)。 在视图控制器中我有三种方法

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight);
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    // some setup
}

然后我从回调中获取触摸并将它们转换到我的坐标系。

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //...
    CGPoint     p=[[touches anyObject] locationInView:nil];
    // some transforms
}

在所有情况下,这在我所有的测试设备(iPhone 3GS - iOS6 和 iPad2 iOS7)上都可以正常工作。但是,在 App Store 发布后,我有两个报告说屏幕旋转后,触摸无法正常工作(iPad 4 和 iPod 4 与 iOS6)。我可能会假设该方法 willAnimateRotationToInterfaceOrientation: 没有被调用,但我对行为的起源有点困惑(适用于具有类似系统的其他设备)。你见过类似的问题吗?

【问题讨论】:

    标签: iphone ios ipad ipod


    【解决方案1】:

    从 iOS6 开始,willAnimateRotationToInterfaceOrientation: 方法不再为不可见的视图控制器调用。因此,如果您的视图控制器呈现另一个接管,则只有另一个会听到这些通知。

    最好将界面定向逻辑移入viewWillLayoutSubviewsviewDidLayoutSubviews,并查询[[UIApplication sharedApplication] statusBarOrientation]属性。

    【讨论】:

    • 谢谢。是的,您的回答是正确的,但真正的问题在很多不同的地方。行为相似。由于使用像素而不是点的屏幕分辨率,触摸坐标被严重转换。在一个方向上是负面的:)
    猜你喜欢
    • 1970-01-01
    • 2019-05-28
    • 2013-12-23
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2012-07-20
    相关资源
    最近更新 更多