UIView not resizing when rotated with a CGAffineTransform under iOS8

前端 未结 3 1622
粉色の甜心
粉色の甜心 2020-12-29 16:45

I have a UIViewController that only rotates some of it subviews when the device is rotated. This works fine under iOS7 but breaks under iOS8. It appears that the UIView\'s b

相关标签:
3条回答
  • 2020-12-29 17:01

    So this was driving me crazy for the past couple days and I was able to fix by changing the timing of the setTransform call in my animations block

    When going to landscape, I'm setting the transform AFTER setting up the new frame. When going portrait, I'm setting the transform BEFORE setting up the new frame. All this was going inside the animations block on the "animateWithDuration..." method

    I'm not sure if it will help you directly with your code, but it might spark some inspiration to solve it since we are definitely having a similar issue

    0 讨论(0)
  • 2020-12-29 17:02

    This is more of a work around than a fix so it may not help everybody in similar situations. My problem was that the outer "pinned" view was being resized again after the transform was applied.

    My solution was to change the constraints on the pinned view to be center vertically, center horizontally, and width and height equal a constant.

    Then, in viewDidLoad, I set the height and width of the pinned view's frame to be the height of the main screen. This makes the view square so I don't care if it gets an extra rotate.

    0 讨论(0)
  • 2020-12-29 17:18

    in ios8, uiviewcontrollers need to be resized with uitraitcollections depending on the device orientation. Otherwise, you get a uiview in portrait mode, while the phone oriented in landscape, when you try to rotate it. So the correct steps are to rotate AND override uitraitcollections

    EDIT: I override my uitraitcollection with the following code UITraitCollection *horTrait = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]; UITraitCollection *verTrait = [UITraitCollection traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassCompact]; UITraitCollection *finalTrait = [UITraitCollection traitCollectionWithTraitsFromCollections:@[horTrait,verTrait]]; [self.parentViewController setOverrideTraitCollection:finalTrait forChildViewController:self];

    unfortunately, it doesnt work if the uiviewcontroller im trying to modify does NOT have a parentviewcontroller :'(

    0 讨论(0)
提交回复
热议问题