iOS, orientationchanges, fires in iOS 5 but not in iOS 6 - objective-c

I have an app that presents a UIWebview modally using presentViewController.
Now the root view supports orientation changes and rotates accordingly. I listen to the event UIApplicationWillChangeStatusBarOrientationNotification.
Now I present the modal window using "
presentViewController:navController
animated:YES
completion:nil];
I dismiss using
dismissModalViewControllerAnimated:YES];
now to the issue :
in iOS 6, this works fine and the modal window shows up in whatever orientation its parent was in.
in iOS 5 , the presentViewController or dismissModalViewControllerAnimated forcibly throws
UIApplicationWillChangeStatusBarOrientationNotification!!
Any ideas why?

Try using this orientation notification instead:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];

Related

UIDevice's beginGeneratingDeviceOrientationNotifications doesn't work well

I have a subview in a subclass of UIView. When the device is rotated I want the subview to remove. This is my code:
- (void)awakeFromNib
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged
{
[subview removeFromSuperview];
}
My problem is that even if the device is tilted a little bit, or put on for example a table the subview removes. What can I do to prevent this?
Don't track the device orientation. Track the interface orientation. Use UIApplicationWillChangeStatusBarOrientationNotification instead of UIDeviceOrientationDidChangeNotification, and get the new interface orientation out of the notification's userInfo. (You won't have to do beginGeneratingDeviceOrientationNotifications if you track interface orientation.)

PageViewController with MPMovieViewController

i'm developing an iOS app for the iPad and used the PageView template. I added some buttons which play some video files. Everything works so far, but the problem is that the touch gestures get called for both views.
My view architecture looks like this
I create a MPMovieViewcontroller, set fullscreen mode and add the view to my pageview:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerFinished:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
mediaView = [[MPMoviePlayerViewController alloc] initWithContentURL:mediaURL];
mediaView.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
mediaView.moviePlayer.fullscreen = YES;
mediaView.moviePlayer.view.exclusiveTouch = YES;
[mediaView shouldAutorotateToInterfaceOrientation:YES];
[mediaView setWantsFullScreenLayout:YES];
[mediaView.moviePlayer prepareToPlay];
[mediaView.moviePlayer play];
[self.view addSubview:mediaView.view];
the problem is that if I try to control the volume slider, that gesture turn the pages of the superview of my MPMovieViewController. How can I avoid this?
I ran into the same problem and I ended up removing the UIPageViewController gestures from the main view and then readded them when I was done. In my case, I'm showing a toolbar on the screen when someone single taps on the page view controller and then it fades out going back to the page view controller. To allow taps on the toolbar, I did the following:
// Remove the page controller gestures from the view
for (UIGestureRecognizer *gesture in self.gestureRecognizers) {
[self.view removeGestureRecognizer:gesture];
}
Where self is my extended UIPageViewController and I'm doing this in the method that shows something on the screen. It's going to be a little different in your case, but effectively this should work for you!

youtube full screen video not calling viewWillAppear or viewWillRotate

So I have a UIWebView in which sometimes it has a youtube embedded player in it. When I play it and go to full screen and rotate and then dismiss the video, it doesn't call the viewWillAppear or the willRotateTo.... why is this?? I need to make some view adjustments when the device is rotated, however when the player is presented, for some reason none of these methods are being called. And yes I have shouldAutoRotateToInterfaceOrientation set correctly. Any idea?
You can use following for your UIwebView problem, viewWillAppear or willRotateTo.. never calls on UIWebView. You can detect the end of full screen mode by observing the #"UIMoviePlayerControllerDidExitFullscreenNotification" mode:
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullscreen:)
name:#"UIMoviePlayerControllerDidExitFullscreenNotification"
object:nil];
}
- (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)moviePlayerDidExitFullScreen:(NSNotification *)notification
{
// This is where you do whatever you want.
}
Your controller must be a UIViewController or the viewWillAppear delegate won't be called.

How to close a modal view when the application enter in background on ios

I have a modal view created in a method (there is no reference in the mainview) and I want to do a dismissModalViewControllerAnimated automatically when my app enter in background. How can I do that ?
In the mainview's viewDidLoad, add observer to be notified when app goes to background.
- (void) viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(goToBackground)
name:UIApplicationWillResignActiveNotification object:nil];
}
Define the function goToBackground(). It will be called when the app goes to background
- (void) goToBackground
{
[self dismissModalViewControllerAnimated: NO]; // no need to animate
}
Don't forget to remove the observer
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
You can use a notification. Post a notification from the ApplicationDelegate's method applicationDidEnterBackground:. YOu can call the dismiss method from the modal controller, so add it as observer to the notification center.

Landscape mode resizing

Im developing an application to display a gallery of images by using a UIScrollView, the sliding between images works fine on portrait mode but when changed to landscape mode it shows the image plus a portion of the next image.
If i could get some explanation on how to solve this issue i would be very thankful.
Make sure your UIScrollView and it's parent view have the right UIViewAutoResizing and autoResizesSubViews values.
Then listen for device orientation changes and take appropriate steps (= reposition subviews of the scrollview)
-(void)applicationDidFinishLaunching:(UIApplication *)application {
// ... other things
[[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) {
NSLog(#"Landscape Left!");
}
}