Weird animations when changing NavigationItem prom

2019-04-04 15:35发布

I have these ViewControllers added in storyboard:

enter image description here

None is connected with a custom class, everything is from pure storyboard.

Video on iPhone simulator on iOS7

This only happens when using AutoLayout on iOS7.

Anyone else seen this?

Download sample project of problem

3条回答
成全新的幸福
2楼-- · 2019-04-04 15:59

i think you Press ⌘T. so the Slow animation is start. Check the all Simulator you Use.

Debug->Slow Animation

I attach Image check it. See Image

查看更多
We Are One
3楼-- · 2019-04-04 16:04

Edit 2:

As someone mentionned in the comments, I am unable to reproduce the problem with your sample project. One thing I noticed though, is that your project is configured with a deployment target that is iOS 8.3. Here are the steps to fix that :

Step 1: Select your project in Xcode's Project Navigator. Step 2: Make sure you select your project in the left column of the project editor and not the target Step 3: Select the Build Settings tab Step 4: Modify the iOS Deployment Target to iOS 7.1 or iOS 7.0 depending on which OS you are testing with. Step 5: Build and run.

Hopefully this will help you out.

Edit:

Step1. Select your UIViewController with the label 14 and in the third tab of the right pane of Xcode, enter a Storyboard ID such as vc14.

Step2. Select your UIViewController with the label 12 and in the same tab, enter a custom class such as ViewController.

Step3. Remove the trigger segue action from your Button and replace it by a @IBAction in ViewController

Step4. Add this code to your @IBAction in ViewController :

@IBAction func push(sender: AnyObject) {
    var vc14 = self.storyboard?.instantiateViewControllerWithIdentifier("vc14") as! UIViewController
    vc14.view.layoutIfNeeded()
    self.navigationController?.pushViewController(vc14, animated: true)
}

Explanation:

The weird animation is occurring because layout has never occurred before the segue pushes the UIViewController in the UINavigationController. iOS 7 didn't protect appropriately against such a scenario by manually calling layoutIfNeeded before entering an animation block and when the layout finally occurs, it triggers implicit animations. In the code sample I have given you, I manually trigger layout before pushing the ViewController on the stack in order to avoid this issue.

查看更多
仙女界的扛把子
4楼-- · 2019-04-04 16:06

I think this problem occurs when view is getting autolayout and setting it size to main screen size. In iOS 7 navigation push animation come before view size is set so we can see that animating. Don't worry it works well in iOS 8.0 and later. For iOS 7.0 you can give size of view in viewDidLoad so it can adjust size before it appears.

查看更多
登录 后发表回答