zoukankan      html  css  js  c++  java
  • Landscape UIViewController/UIView Rotation/只支持横屏

    1. In the "info.plist" file, setting the following property:

    Code:
    <key>UIInterfaceOrientation</key>
        <string>UIInterfaceOrientationLandscapeRight</string>


    2. In the "applicationDidFinishLaunching" of the app delegate, calling the following code:

    Code:
    // Make the window active
    [window makeKeyAndVisible];
    
    // Now try to set the orientation to landscape (right)
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

    3. Finally, implementing this method in the view controller:

    Code:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }


    This gets me very close... it is a little hard to describe what it does, but heres goes nothing:

    1. The application launches with the status bar in landscape, but the rest of the screen is black.
    2. The view then appears (it is an EAGLView), but in portrait.

    3. The view immediately rotates to the proper landscape orientation with the animation is if the user had rotated the device.

    If you're looking to rotate your UIView programmatically, instead of when the phone physically changes orientation... try this code in your UIView or UIViewController:

    Code:
    // Rotates the view.
    CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
    self.view.transform = transform;
    	
    // Repositions and resizes the view.
    CGRect contentRect = CGRectMake(-80, 80, 480, 320);
    self.view.bounds = contentRect;
    View rotation uses radians instead of degrees... so a 90 degree rotation is pi / 2 (thank god Wikipedia has an article on radians!)

    When you rotate the view, if you don't resize and reposition it... you'll find that it's origin point (it's top left corner with the phone held landscape style) is at the top edge, but about a half an inch indented. The result is there is a chunk of the screen on the left and right that is not touchable. Resizing and repositioning fixed that for me.

    id 博主 = [[KILONET.CNBLOGS.COM alloc] initWithValue:@"天堂向右,我依然向左"

                  网名:@"老舟"

                  兴趣:@"影音,阅读"

                  动态:@"系统架构设计,Android通信模块开发"

                  网址:@"http://kilonet.cnblogs.com"
                  签名:@"--------------------------------------------------

                                  Stay Hungry , Stay Foolish

                                  求  知  若  渴,处  事  若  愚

                              --------------------------------------------------"

                  ];         // Never Release

  • 相关阅读:
    Jenkins+Docker+Git+Harbor流水线打包
    docker镜像批量打包
    二进制安装docker-18.06.3-ce
    kubeadm添加新master或node
    Host is not allowed to connect to this MySQL server
    RecyclerFullyManagerDemo【ScrollView里嵌套Recycleview的自适应高度功能】
    RecyclerSwipeAdapterDemo【使用AndroidSwipeLayout用于列表项侧滑功能】
    RecyclerViewItemTouchHelperDemo【使用ItemTouchHelper进行拖拽排序功能】
    Android APP应用启动页白屏(StartingWindow)优化
    KeyboardUtil【软键盘弹出后输入框上移一定的高度】
  • 原文地址:https://www.cnblogs.com/KiloNet/p/1803333.html
Copyright © 2011-2022 走看看