zoukankan      html  css  js  c++  java
  • 屏幕旋转

    设置是否允许屏幕旋转

    - shouldAutorotate{

        return YES;

    }

    设置可旋转的方向

    - supportedInterfaceOrientations{

        return UIInterfaceOrientationMaskAll;

    }

     iOS8之前的屏幕旋转的方法,之后已经被弃用,但是现在依然可以使用.

    //当将要开始旋转的时候触发

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

        //该方法中,一般做暂停音乐,关闭用户交互等操作

        NSLog(@"将要开始旋转了");

    }

    //旋转完成时触发

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

        //该方法中,一般做重新开启音乐,打开用户交互等操作

        NSLog(@"已经完成屏幕旋转了");

    }

    //当开始做旋转动画时触发

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

        //可以自定义旋转的动画效果

    }

    #warning iOS8之后使用这个方法代替

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{

        

    }

    当屏幕旋转时会触发layoutSubviews方法,可以在此方法中重新布局子视图

    //当视图的子视图的位置将要发生变化的时候会调用该方法重新布局视图的子视图.

    //当对子视图设置frame时与将子视图放到父视图上时,系统分别调用layoutSubviews方法.

    - (void)layoutSubviews{

        //获取手机状态栏的位置,以判断应用程序当前的位置.

        UIInterfaceOrientation location = [UIApplication sharedApplication].statusBarOrientation; //单例

        switch (location) {

            case UIInterfaceOrientationUnknown: {

                NSLog(@"发生未知错误");

                break;

            }

            case UIInterfaceOrientationPortrait:

            case UIInterfaceOrientationPortraitUpsideDown: {

                self.btn.frameCGRectMake(kButtonSpaceLeft, kButtonSpaceTop, kButtonWidth, kButtonHight);

                break;

            }

            case UIInterfaceOrientationLandscapeLeft:

            case UIInterfaceOrientationLandscapeRight: {

    //            CGRect frame = self.btn.frame;

                self.btn.frame = CGRectMake(kButtonNewSpaceLeft, kLabelSpaceTop, kButtonWidth, kButtonHight);

                break;

            }

            default: {

                break;

            }

        }

    }

  • 相关阅读:
    Core Data
    scrollViews
    网络通信
    UIView
    textView取消键盘
    AFNetworking转载
    多线程
    css3[转载][菜单导航] 带有记忆功能的多页面跳转导航菜单
    jQuery翻牌或百叶窗效果
    jQuery联动日历(三)完成
  • 原文地址:https://www.cnblogs.com/lion-witcher/p/5155654.html
Copyright © 2011-2022 走看看