0

我有一个 UIViewController 子类,它会在 UI 旋转时更改其框架(例如,最常见的是,框架大小相同,并且以横向和纵向为中心。)当视图旋转时,视图在视觉上会按预期更改其框架。但是最终在新框架区域中的控件(按钮、滚动视图等)不会响应触摸。唯一响应的控件是保留在原始框架中的控件(因此,如果视图向下和向左移动,右上角的控件或控件的一部分保持响应。)知道这里发生了什么吗?

这是更改框架的代码:

- (void) setLandscape:(bool)bLandscape {

    if( bLandscape )
        [self setFrame:m_landscapeFrame];
    else
        [self setFrame:m_portraitFrame];
}

在直接处理旋转的更大视图控制器中:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    bool bToLandscape= UIInterfaceOrientationIsLandscape(toInterfaceOrientation);

    [UIView beginAnimations:NULL context:nil];
    [UIView setAnimationDuration:duration];

    [m_pCurrentWindowViewController setLandscape:bToLandscape];

    // (Some unrelated stuff happens here...)

    [UIView commitAnimations];

}

对我来说,这似乎是苹果的一个错误或至少是糟糕的设计 - 永远不应该有一个时间视图在视觉上处于一个位置而在控制方面处于另一个位置。但我只是在寻找一种方法来解决这种行为。

4

1 回答 1

1

我发现的最简单的解决方法是didRotateFromInterfaceOrientationwillRotateToInterfaceOrientation.

于 2012-07-17T22:30:26.467 回答