zoukankan      html  css  js  c++  java
  • 如何实现ios屏幕的横竖屏自适应(转)

    如何实现ios屏幕的横竖屏自适应

    首先在UIViewController的
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    方法中设置设备要支持的deviceOrientation;
    在UIViewController的
    -(void)willRotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation 
    duration:(NSTimeInterval)duration
    或者
    -(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
    duration:(NSTimeInterval)duration
    重新设置所有子view的frame
     
    当UIView设置成自动适配屏幕(即myView.autoresizesSubviews = YES)时,当我们重新设置myView的frame时(一般屏幕旋转时我们都会重新设置view的frame),会自动调用 layoutSubviers方法,我们可以在该方法中判断屏幕的方向,并调整各子view的frame。
     
    如果工层中有一个superViewController,然后在该控制器的试图上加上了另一个subViewController的 view,无论如何subViewController的以上三个方法都不会被调用,这个时候,可以在superViewController的
    -(void)willRotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation 
    duration:(NSTimeInterval)duration
    或者
    -(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
    duration:(NSTimeInterval)duration
    方法中重新配置subViewController的view。
  • 相关阅读:
    c++ stack 适配器
    错误记录
    css3动画,制作跑步运动,画笔画圆,之类的连贯性动作的方法
    关于$.cookie
    JavaScript中常见易犯的小错误
    关于内存泄漏
    Javascript的异步编程方法
    JavaScript中this关键词的四种指向
    javascript之回调函数小知识
    移动端的兼容性
  • 原文地址:https://www.cnblogs.com/yaoliang11/p/2810988.html
Copyright © 2011-2022 走看看