开发者

How to detect the orientation of the subview of a class added on other class view?

开发者 https://www.devze.com 2023-03-24 21:16 出处:网络
I want to detect the orientation(i.e Landscape or portrait) of the subview of the class which I have added on other class view controller. In other words, I have added a subview of the class viewcontr

I want to detect the orientation(i.e Landscape or portrait) of the subview of the class which I have added on other class view controller. In other words, I have added a subview of the class viewcontroller to the other cl开发者_StackOverflowass view controller. and now I want to detect the orientation of that view.

How can I do this?


Try:

subViewController.interfaceOrientation


To have a clean interface, you could create a category class for UIApplication and return interfaceOrientation on these lines:

- (UIInterfaceOrientation)my_interfaceOrientation { return [objc_getAssociatedObject(self, &interfaceOrientationKey) intValue]; }


Sometimes viewController.interfaceOrientation doesn't seem to work quite well, you probably should better go with [[UIApplication sharedApplication] statusBarOrientation] assuming that you don't do any "dirty" hacks on the user interface!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号