简体   繁体   English

iOS-UIView子类不会随设备一起旋转

[英]iOS - UIView subclass won't rotate with device

I have a custom UIView that I use to display synchronization in my device, but it won't rotate with the device when the orientation changes. 我有一个自定义UIView,用于在设备中显示同步,但是当方向更改时,它不会随设备一起旋转。 Everything else rotates just fine, is there something I am missing to ensure my subclassed uiview will rotate? 其他所有内容都可以正常旋转,我是否缺少某些东西来确保我的uiview可以旋转?

Programmatically: 以编程方式:

 - (BOOL)shouldAutorotate{
        return YES;
    }

add this. 添加。 Hope this helps.. 希望这可以帮助..

Or go to your Target Settings and click the directions you want it to rotate, but this will affect all your viewcontrollers. 或转到“目标设置”,然后单击要旋转的方向,但这会影响所有的视图控制器。

You can follow any of the following methods, 您可以采用以下任何一种方法,

1-Create a class to subclass the UIView and override the shouldAutorotate in .m(implementation file). 1-创建一个类来继承UIView并重写.m(实现文件)中的shouldAutorotate。 Now include this custom UIView class in your viewController to create objects. 现在,在您的viewController中包含此自定义UIView类以创建对象。

2-Creating category for the UIView class 2-为UIView类创建类别

NOTE:- if your building app to support iOS6 then don't forget to include the methods which apply for your requirement 注意:-如果您的建筑应用程序支持iOS6,那么请不要忘记包括适用于您的要求的方法

 >>>>>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
 >>>>- (BOOL)shouldAutorotate;
 >>>>- (NSUInteger)supportedInterfaceOrientations;
 >>>>- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

Example For Category:- 类别示例:-

       @interface UIView (Additions)

       @end

       @implementation UIView (Additions)

           - (BOOL)shouldAutorotate{
              return YES;
                    }

       @end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM