How to change view of the viewcontroller when change the orientation in iPhone?

后端 未结 3 886
悲哀的现实
悲哀的现实 2021-01-28 19:13

I\'m developing an iPhone application which supports 2 orientations. I have 2 UIView files for this view controller. I need to set corresponding UIView file to the view controll

3条回答
  •  盖世英雄少女心
    2021-01-28 20:09

    Assuming you have set the -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation to return your supported orientations, you can use the following methods which can all be set in your UIViewController to check for orientation changes and then set your views:

    // called just before the user interface starts to rotate - my advice would be to use this method to save a copy of the current orientation.
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    
    // called after the interface has finished rotating. Here, you can compare the old orientation with the new one - if you went from portrait to landscape, then update your views accordingly.
    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    

    Hope this helps!

提交回复
热议问题