bobbyali / kidsvidz

KidsVidz - Simple and Safe iOS YouTube player for young children
0 stars 1 forks source link

Rotation bug - won't render upsidedown properly #1

Closed bobbyali closed 9 years ago

bobbyali commented 9 years ago

The screen won't render properly when screen orientation is set to PortraitUpsideDown (i.e. after 2 successive orientation changes in the same direction).

bobbyali commented 9 years ago

I'm tracking the orientation in these lines https://github.com/bobbyali/kidsvidz/blob/master/KidzVids/GridViewController.swift#L151-L154 with this code:

let rotationVal = UIApplication.sharedApplication().statusBarOrientation.rawValue

When I load the simulator (typically iPhone 5/6) and do rotations, I see the following values produced:

Rotated 1 h: 548.0 w: 320.0
Rotated 4 h: 320.0 w: 568.0
Rotated 4 h: 320.0 w: 568.0
Rotated 3 h: 320.0 w: 568.0
Rotated 1 h: 548.0 w: 320.0

i.e. it skips value 2 after two turns (when it is in PortraitUpsideDown mode). When this happens, and the current rotationVal is repeated (either 3 or 4), and the screen height/width attributes don't update properly, the screen doesn't update properly (see screenshot below). I can't figure out why this is happening.

screenshot_bad_rotation

bobbyali commented 9 years ago

After chat with Tudor:

Deployment settings - need to enable "Upside Down"!

    override func supportedInterfaceOrientations() -> Int{
        return Int(UIInterfaceOrientationMask.All.rawValue)
    }

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

override func shouldAutoRotate

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/shouldAutorotate

Also see screenshot at http://monosnap.com/image/2y0Fbcn3G2sQDw6ZmsYPbxAfquzQyi

bobbyali commented 9 years ago

Tudor figured this out:

https://github.com/bobbyali/kidzvids2/compare/master...tudormunteanu:master http://stackoverflow.com/questions/18562892/view-controller-doesnt-autorotate-to-portait-upside-down