zoukankan      html  css  js  c++  java
  • ios成长之每日一遍(day 5)

    iOS 屏幕方向那点事儿
    http://zhenby.com/blog/2013/08/20/talk-ios-orientation/

    针对当前的屏幕方向进行对应的代码布局

    BIDViewController.m

    #import "BIDViewController.h"
    
    @interface BIDViewController ()
    
    @end
    
    @implementation BIDViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        UIApplication *app = [UIApplication sharedApplication];    // 获取单例UIApplication
        UIInterfaceOrientation currentOrientation = app.statusBarOrientation;    // 获取当前状态栏的方向
        [self doLayoutForOrientation:currentOrientation];
    }
    
    // 用于横纵屏变化的时候的切换用portrait和landscape是两个视图
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [self doLayoutForOrientation:toInterfaceOrientation];
    }
    
    - (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation {
        if (UIInterfaceOrientationIsPortrait(orientation)) {    // 屏幕在垂直方向
            _bigButton.frame = CGRectMake(20, 20, 280, 280);    // 重新绘画控件的位置大小
            _actionButton1.frame = CGRectMake(20, 320, 120, 40);
            _actionButton2.frame = CGRectMake(20, 400, 120, 40);
            _actionButton3.frame = CGRectMake(180, 320, 120, 40);
            _actionButton4.frame = CGRectMake(180, 400, 120, 40);
        } else {    // 屏幕在横屏方向
            _bigButton.frame = CGRectMake(20, 20, 260, 260);
            _actionButton1.frame = CGRectMake(320, 20, 120, 40);
            _actionButton2.frame = CGRectMake(320, 90, 120, 40);
            _actionButton3.frame = CGRectMake(320, 160, 120, 40);
            _actionButton4.frame = CGRectMake(320, 230, 120, 40);
        }
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    BZOJ1222: [HNOI2001]产品加工(诡异背包dp)
    洛谷P1208 [USACO1.3]混合牛奶 Mixing Milk(贪心)
    SDOI 2018划水记
    【Leetcode】Search in Rotated Sorted Array II
    HDU 4089 Activation
    linux scp ssh命令不用输入密码
    封装fastjson为spring mvc的json view
    codility上的练习(3)
    git 拉取远程分之到本地
    Oracle 索引扫描的4种类型
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/3745209.html
Copyright © 2011-2022 走看看