Reputation: 139
I am using this code
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
UIView * videoView = [[window subviews] lastObject];
[videoView addSubview:viewFullScreenToolbar];
to add a view on topmost view to play video on fullscreen. When the fullscreen button is pressed, this code executes and presents a fullscreen video. But when fullscreen is closed and then pressed again, the viewFullScreenToolbar is not visible although the video is playing correctly in fullscreen. Plus the problem is only in landscape mode, it works good in portrait mode.
Upvotes: 0
Views: 2747
Reputation: 139
Its seems so obvious once you find the answer. So, all I had to do was register for the orientation change notification.
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(ChangeOrientationIfFullScreen:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
And in the method called when the notification is received, I had to set the frames of the subviews manually for each orientation change. It was a bit of overhead but finally achieved a smooth transition on the screen.
Upvotes: 0
Reputation: 1697
Are you trying to add a subview to the fullscreen MPMoviePlayerController view?
Yes. You do need to add the subview in a hacky way (similar to what you list) because MPMoviePlayerController provides no hooks to the fullscreen video view. Your issue is likely related to this subview not getting rotation callbacks.
No. If you own this videoView then you shouldn't access the view using UIWindow. You should access it through its view controller. Then when you add your toolbar as a subview it will receive rotation callbacks.
If you situation is #1 I can help further but want to check first.
[Update]
If you want add an overlay view to the MPMoviePlayerController fullscreen view you have three options:
Adding an overlay view to the MPMoviePlayerController fullscreen view is not straightforward because the fullscreen view is not accessible from the MPMoviePlayerController API. It requires accessing the view through the window, adding the subview and then manually handling the rotation callbacks. Pain in the $%^*.
Please do not use this approach for any other situation.
Upvotes: 0
Reputation: 666
This should serve your purpose--
AppDelegate *appD=(AppDelegate *)[[UIApplication sharedApplication] delegate];
[appD.window addSubview:viewFullScreenToolbar]; [appD.window bringSubviewToFront:viewFullScreenToolbar];
Upvotes: 2
Reputation: 9553
This is...not a good way to do what you want. Don’t rely on a particular window being the “first” window, and don’t rely on a a particular view being the “last” subview. Those things are too subject to change.
Create IBOutlets on the windows and views you want to use, hook them up in the .XIB file, and refer to them directly.
Upvotes: 5