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是两个视图。

  • 相关阅读:
    Python小工具:统计代码行数
    计算机图形学复习(一)
    牛客多校训练第一场 J.Different Integers
    数据校验码概述
    数据库复习第二章
    数据库复习第一章
    自动化AC器(带界面版)
    ZOJ 3747 Attack on Titans
    Codeforces Round #245 (Div. 1) B. Working out
    HDU 6266 Hakase and Nano 【博弈论】
  • 原文地址:https://www.cnblogs.com/iphone520/p/2211191.html
Copyright © 2011-2022 走看看