Wednesday 30 July 2014

How to set view for particular orientation in any view forcefully?



Here using this bellow code you can set any orientation forcefully to any view...


[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")

                                                                      withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];

after put this code you get warning that "PerformSelector may cause a leak because its selector is unknown"

for remove this code you can use this above code with bellow solution...

First define the bellow code in your .m file

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

after use that above code with bellow method...

SuppressPerformSelectorLeakWarning(
         [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                                                      withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
    );

you can use this code in viewDidLoad method or anywhere in which you want to display whole view in particular orientation forcefully

No comments:

Post a Comment