Stop Screen From AutoRotating, but Keep UIWebView Rotation - ios

I have a UIWebView in my viewcontroller that is embedding a YouTube video and when the user clicks it, it plays the video. I want the webview to be able to rotate, but not the viewcontroller that it's being held on. Are there any solutions out there for this problem? This is an iOS6 and above supported application.

In your shouldAutorotateToInterfaceOrientation method, change the UIWebView to the new orientation, then return NO.
This way the view controller will stay the way it is, but you can do whatever you need to do to the UIWebView to make it display correctly in the new orientation.

Related

Layout Constraints Only Applied In Certain Conditions When Size Class Changes

I have a container view controller which contains 2 views. One is a video and the other is chat. In portrait mode, the user can see both the video and the chat; however, in landscape, I want it to only show the video.
What I've done:
I use size classes and for wCompact and hCompact (iPhone 6 landscape), I remove the chat view and update the constraints. It 'partially' works.
If I start my application in landscape, the video will be shown in full. When I rotate to portrait, I get both the video and chat views. Finally, if I rotate it back to landscape, I only get the video view again. This is the desired behavior. See this GIF:
The problem:
If I start the app in portrait, it shows both the video and chat view. Then, when I rotate it to landscape, the chat view is removed but the video view does not update to its new layout constraints. See the GIF below:
I suspect this has something to do with the view using a MPMoviePlayerController or the fact that it's fetching/streaming data. I don't know.
I'm not even sure what to google to help with this so if anyone has anything, please let me know.
Thanks much!
Solution: Use AVPlayerViewController and AVPlayer. It just works. MPMoviePlayerController is buggy

Media Player force landscape

In my app I want a video to open in landscape mode when the MediaPlayer is being opened, but I don't want to enable landscape in all other ViewControllers. How can I programmatically achieve this using Swift?
You need to declare method viewWillTransitionToSize:withTransitionCoordinator: in your view controller, and change frame relatively to your needs.
In more detail, you need to read here, at least.

MPMoviePlayerController dismissing full screen mode not working in iOS 6

The MPMoviePlayerController working fine in iPad with iOS 5, initially the video starts by adding MPMoviePlayerController to subview of self at certain frame .Pressing full screen button on MPMoviePlayerController embedded controls displaying the movie in full screen,again tapping the button will bring the video back to the initial frame in iOS 5. But in iOS 6, the when I press full screen button to bring the video to initial frame, the video just gone out of screen. Looks like Apple has made some undocumented change to MPMoviePlayer class that is causing this weird behaviour. Anyone having the fix for this?
I have fixed this issue myself, in iOS 6, apple has made some undocumented changes to MPMoviePLayerController class, when you tap on full screen button, the viewWillDisappear and viewDidDisAppear gets called for both the controller launching MPMoviePLayerController and its ParentController.
In My Project (a pdf reader), I have a very complex view hierarchy, adding a reader in view Controller, then adding the readerPageContents buttons(image Gallery, video, link) to reader page and then playing video on video button tap.So it was calling the ViewWillDisappear and ViewDidDisappear when launching the video in full screen, and when when I press toggle screen button to bring the video to initial frame, the ViewWillAppear and ViewDidAppear of both controllers called again and I was creating the pdf page again in parent's controller viewDidAppear which was removing the video.
So easier fix it to avoid ViewDidDisappear and ViewWillDisappear gets called by setting some BOOL.

how to fix youtube video in uiwebview from playing behind parent view controller

I have implemented TTPhotoViewController in my app and it is working fine. However, it seems to have broken the landscape orientation on the the only view controller that rotates in my tabbarcontroller (subclassed). I have also returned NO in - (BOOL)shouldAutorotateToInterfaceOrientation: in my subclassed TTphotoviewcontroller and TTThumbviewcontrollers to stop landscape orientation of the photo gallery.
The view controller that previously was able to orientate to landscape plays youtube videos. The view controller loads a list of videos (youtube mobile page) but now when you select a video to play the file plays in the iOS movieplayer in landscape (which is a good thing) but BEHIND the parent view controller which remains in portrait.
I have removed the code to force the video view controller to orientate to landscape and the behaviour persists, which makes me think it is something to do with a file in the Three20 library.
Any ideas?

How to prevent my MPMoviePlayerController from getting black when back from a webView containing a YouTube Video - iOS

Here is the context :
NavigationController -> FirstViewController -> SecondViewController
FirstViewController display a MPMoviePlayerController in embedded mode, and buttons to go to SecondViewController. This MPMoviePlayerController is reading a local .m4v file.
SecondViewController display a UIWebView with web pages containing YouTube videos.
Here are the steps :
the user read the video on FirstViewController (works fine)
the user press one of the buttons to go to SecondViewController
the user press one of the youtube video, that will play in embedded mode in the webView (works fine too)
the user press the Back button in NavigationItem
The problem appear at this particular moment :
When the user come back from SecondViewController, the MPMoviePlayerController is black.
I tried using prepareToPlay on the moviePlayer in viewWillAppear and/or viewDidAppear. In both cases, I got a good result for half a sec and then the MoviePlayer view is turned to black again.
I think that when the viewDidUnload is called in the SecondViewController, something happen that put a brief access to the web embbedded MoviePlayer.
Any idea about how to solve the problem ?
Note : this only appear on a device because videos don't appear on UIWebView in simulator. I tried to reproduce it with another MPMoviePlayerController in the second view but putting a prepareToPlay in the viewDidAppear solved it...
Note 2: this problem only appear on iPad. I tried to reproduce it on iPhone but the youtube player won't play video in embedded mode on iPhone...
There should be no movie player code. Just put your video url on your web view code it shall work fine.

Resources