I am having a MPMoviePlayerView that i am creating programatically.My PlayerView auto rotation works fine with iOS 5 but it do not work in iOS 6 and iOS 7.I had tried adding orientation detection but problem remain same.
Can anyone tell me how can i support auto rotation in iOS 5 ,iOS 6 and iOS 7.
Thanks ,
Try to implement this method in AppDelegate:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
}
you can make condition here for both mode.
such as if media player is in full screen then
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
otherwise return UIInterfaceOrientationMaskPortrait;
thanks
[[UIApplication sharedApplication] statusBarOrientation];
[[UIDevice currentDevice] orientation];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceRotatedEventList:) name:UIDeviceOrientationDidChangeNotification object:nil];
-(void)deviceRotatedEventList:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//Do your stuff for landscap
}
else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
}
//For rotation method write ur code potraite and landscape mode whatever........
Related
I have created an iphone app which is only in portrait orientation,even though i have made one view supporting landscape orientation also while rotating the device
Everything works fine in iOS6 but when i run it on iOS5,the landscape mode is not proper it shows some nasty images.
(both devices are ipod 3.5" retina display)
Why is this happening??
Adding my codes and screen shots here
In iOS6
in iOS 5
-(void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[notification object] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
[self.grpView setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
imageScrollView.frame =CGRectMake(-50, -100, 400, 620);
} else if (orientation == UIDeviceOrientationLandscapeRight) {
[self.grpView setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
[self.grpView setTransform:CGAffineTransformMakeRotation(M_PI)];
} else if (orientation == UIDeviceOrientationPortrait) {
[self.grpView setTransform:CGAffineTransformMakeRotation(0.0)];
}
}
InterfaceOrientation method is got deprecated in ios6.
So that if you want your orientation supported by both ios5 & ios6, you have to write two extra methods for ios6 along with
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// your customisation will go here
}
Two extra methods for ios6
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
// your customisation will go here
}
Enjoy Programming!
I have a Tab bar application. I was using XCode 4.3.3. I have upgraded to 4.5.2 with iOS6 stuffs.
My code in the shouldAutorotateToInterfaceOrientation for each view will check the current device orientation and place all the UI components properly.
But after upgrading to iOS 6, this code is not executing. I have tried for almost one day to fix this, but had no luck.
I have also tried
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
in viewLoad, viewDidLoad, viewWillAppear
What should I do if I want to check the orientation during the view load and place the UI components to appropriate places during view load. Kindly give your suggestion.
Thanks
if you want to check which is current orientation, then you just write in prifix.pch below line
#define isPortrait [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown
then where you want to check orientation ,write condition like below
if(isPortrait)
{
//portrait mode....
}
else
{
//landscape mode....
}
let me know it is working or not...
Happy coding!
To check orientation in ios6,you will have to write below methods and also in your info.plist you will have to define which orientation you want...
let me know whether it is working or not!!!
Happy Coding!!!!
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;//you can write here which ever orientation you want..
}
you manage Oriantation like this ways:-
-(BOOL)shouldAutorotate
{
return YES;
}
and check every time in ViewWillApear device Oriantation like:-
- (void)willRotateToOrientation:(UIInterfaceOrientation)newOrientation {
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {
//set your landscap View Frame
[self supportedInterfaceOrientations];
}
}
else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
//set your Potrait View Frame
[self supportedInterfaceOrientations];
}
}
// Handle rotation
}
-(void)viewWillAppear:(BOOL)animated
{
[self willRotateToOrientation:[[UIDevice currentDevice] orientation]];
[super viewWillAppear:YES];
}
UPDATE
likely people use checking deviceorientation like below way in putting this line in to ViewWillApear:-
[[UIApplication sharedApplication] statusBarOrientation];
[[UIDevice currentDevice] orientation];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];
and
-(void)deviceRotated:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//Do your stuff for landscap
}
else if(orientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do your stuff for potrait
}
}
At viewDidLoad method you need to check for the same and accordingly you need to write code unless it may affect view if it not in on portrait.
I have this code and it works perfectly on iOS 5 but not on iOS 6 please help
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
return (orientation != UIDeviceOrientationPortrait) &&
(orientation != UIDeviceOrientationPortraitUpsideDown);
}
let try this :
First inside viewDidLoad function use this code :
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
}
then, i'm create function that will receive notification for two lines of code :
- (void)orientationChanged:(NSNotification *)object{
NSLog(#"orientation change");
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
if(deviceOrientation ==UIInterfaceOrientationPortrait){
NSLog(#"Changed Orientation To Portrait");
// Handle your view.
}
}else{
if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
NSLog(#"Changed Orientation To Landscape left");
// Handle your view.
}else{
NSLog(#"Changed Orientation To Landscape right");
// Handle your view.
}
}
}
i hope my answer will help. Cheers.
In iOS6, "shouldAutorotateToInterfaceOrientation" method is deprecated.Try setting orientation in plist file.
I'm basically running this code:
UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(statusBarOrientation == UIInterfaceOrientationPortrait){
NSLog(#"orientation is portrait");
}
However, regardless of the actual orientation in the simulator or my iPad, it is printing "orientation is portrait". Trying to NSLog the statusBarOrientation as a %d also returns 1 no matter what the orientation.
I've stuck this is my app delegate, my view controller, and the class that I need it in, and its the same thing. All 4 device orientations are supported in my info.plist / target settings.
Does anyone have a sure fire way of figuring out the interface orientation, or why mine is not working? Thanks
if you dont like to used Notification for orientation.. Then use below method too.
this is example of Only Landscape Orientation in iPad and Portrait in iPhone...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(interfaceOrientation==UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
return YES;
else
return NO;
}
else
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
You can REGISTER FOR notifications on orientation changes:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didRotate:)
name:#"UIDeviceOrientationDidChangeNotification"
object:nil];
- (void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)) {
// DO STUFF
}
else if (orientation == UIDeviceOrientationPortrait) {
//DO MORE STUFF
}
}
Currently you are returning the orientation of the status bar. Instead get the orientation of the device: [[UIDevice currentDevice] orientation]
How to get the current orientation of iPhone?
I surfed this site, and found two methods as followings.
[UIApplication sharedApplication].statusBarOrientation;
[[UIDevice currentDevice] orientation];
Which one is the right way to get the current orientation ?
I tried two methods under simulator 4.1, but there are some problems for both methods.
Register your class to listen to UIDeviceOrientationDidChangeNotification then handle the device orientation accordingly.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(deviceRotated:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
and handle the device's orientation properly:
- (void)deviceRotated: (id) sender{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationFaceUp ||
orientation == UIDeviceOrientationFaceDown)
{
//Device rotated up/down
}
if (orientation == UIDeviceOrientationPortraitUpsideDown)
{
}
else if (orientation == UIDeviceOrientationLandscapeLeft)
{
}
else if (orientation == UIDeviceOrientationLandscapeRight)
{
}
}
[[UIDevice currentDevice] orientation] gets the current physical orientation of the device. [UIApplication sharedApplication].statusBarOrientation gets the orientation of the UI. If the app ever returns NO to the shouldAutorotateToInterfaceOrientation: method, the two values will not be the same.