zoukankan      html  css  js  c++  java
  • [IOS]iphone开发之横屏与竖屏在不同视图之间的切换

    有两个视图,横屏视图和纵屏视图,当iphone的方位变化的时候,这两个视图相互切换。

    1。两个视图:PortraitView和LandscapeView ,分别标示纵屏和横屏。

    2。一个控制器,RootViewController,根控制器。

    3。在RootViewController.m中有以下代码

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
    [landscape removeFromSuperview];
    [self.view addSubview:portrait];
    }
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
    [portrait removeFromSuperview];
    [self.view addSubview:landscape];
    }
    }


    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {

    UIControl *back = [[UIControl alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    back.backgroundColor = [UIColor grayColor];
    self.view = back;
    [back release];

    }



    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];

    portrait = [[PortraitView alloc] initWithFrame:CGRectMake(10, 10, 300, 440)];
    portrait.backgroundColor = [UIColor yellowColor];
    [portrait addButton];


    landscape = [[LandscapeView alloc] initWithFrame:CGRectMake(10, 10, 460, 280)];
    landscape.backgroundColor = [UIColor greenColor];

    [self.view addSubview:portrait];

    }

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.

    return YES;

    }

    分析:willAnimateRotationToInterfaceOrientation方法是用于横纵屏变化的时候的切换用。

    portrait和landscape是两个视图。

  • 相关阅读:
    二维数组实现01背包
    一维数组实现01背包
    js实现最长子串算法
    mysql__存储过程
    mysql 分页查询 limit
    转:严重: Exception loading sessions from persistent storage
    struts2---ValueStack对象
    struts2----ognl
    什么是JavaBean?
    EL表达式
  • 原文地址:https://www.cnblogs.com/iphone520/p/2211191.html
Copyright © 2011-2022 走看看