开发者

Objective-c Change view when iphone is horizontal

开发者 https://www.devze.com 2023-02-20 14:57 出处:网络
How do I know when the iphone is vertically or horizontlly? I want to switch views depending on the iph开发者_StackOverflow社区one orentation.

How do I know when the iphone is vertically or horizontlly? I want to switch views depending on the iph开发者_StackOverflow社区one orentation.

Thanks


In a UIViewController subclass, you can override one (or more) of these methods:

  • willRotateToInterfaceOrientation:duration:
  • willAnimateRotationToInterfaceOrientation:duration:
  • didRotateFromInterfaceOrientation:
  • willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
  • didAnimateFirstHalfOfRotationToInterfaceOrientation:
  • willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:

From the documentation notes for willRotateToInterfaceOrientation:duration::

Subclasses may override this method to perform additional actions immediately prior to the rotation. For example, you might use this method to disable view interactions, stop media playback, or temporarily turn off expensive drawing or live updates. You might also use it to swap the current view for one that reflects the new interface orientation. When this method is called, the interfaceOrientation property still contains the view’s original orientation.

Like so:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
    {
        // do a thing
    }

    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
             toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        // some other thing
    }
}
0

精彩评论

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