andreamazz / BubbleTransition

A custom modal transition that presents and dismiss a controller with an expanding bubble effect.
MIT License
3.32k stars 250 forks source link

Transition lag? #14

Closed acegreen closed 8 years ago

acegreen commented 8 years ago

Hello @andreamazz ,

First of thanks for the great work. Library works awesome.

I'm not sure if my problem is directly linked to bubbleTransition, but I'm noticing a lag on the FIRST button press. From there on after, its smooth as butter.

Note: The startingPoint is incorrect because it appears somewhere on the top though I don't think its CGPointZero but a little under the navigation bar and centered horizontally. This is weird because I specified it as below and that button is at the bottom of the screen. I'm not sure if the button lagged without bubbleTransition.

@IBOutlet var starButton: SpringButton! 

I create the segue using storyboard and just do:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "feedback" {
        let controller = segue.destinationViewController
        controller.transitioningDelegate = self
        controller.modalPresentationStyle = .Custom
    }
}

extension ViewController: UIViewControllerTransitioningDelegate {

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    transition.transitionMode = .Present
    transition.startingPoint = starButton.center
    transition.bubbleColor = UIColor(red: 245.0/255.0, green: 192.0/255.0, blue: 24.0/255.0, alpha: 1)
    return transition
}

func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    transition.transitionMode = .Dismiss
    transition.startingPoint = starButton.center
    transition.bubbleColor = UIColor(red: 245.0/255.0, green: 192.0/255.0, blue: 24.0/255.0, alpha: 1)
    return transition
}

}

acegreen commented 8 years ago

More info: Ended up having to calculate my starButton center by converting it first.

    let center = starButton.superview!.convertPoint(starButton.center, toView: self.view)
    transition.startingPoint = center

Now the bubble starts from the button. But there is still the first time lag.

andreamazz commented 8 years ago

It might be related to what your view is loading. Is there by any chance a mapkit object inside? I always notice a considerable lag the first time I load a map view.

acegreen commented 8 years ago

Yea I know what you mean. Had that before but my current segue is super simple and the VC is basically empty. Also the segue perform perfectly from the second time onwards. It's only the first time that it needs to think for a little.

Also I got the whole idea from another project and in that project there is no lag the first time around. Also nowhere else is there a lag to find in my project except with that one button segue.

andreamazz commented 8 years ago

So if you remove the custom transition and use the basic modal, the lag disappears?

acegreen commented 8 years ago

Let me try that.

acegreen commented 8 years ago

device update to iOS 9.2 overnight so give me 5 minutes.

acegreen commented 8 years ago

@andreamazz i removed the transition by removing the code in PrepareForSegue but seems to also be a lag there the first time.

andreamazz commented 8 years ago

It shouldn't be related to the bubble then. Time to fire up the time profiler :grin:

acegreen commented 8 years ago

He issue is described here exactly as I'm seeing it: http://stackoverflow.com/questions/28509252/performseguewithidentifier-very-slow-when-segue-is-modal

I perform the segue on storyboard so how according to the solution I would need to perform the segue programmatically and use dispatch.

What do you think?

andreamazz commented 8 years ago

Might be worth a try, still it's pretty weird, I never encountered this issue.

acegreen commented 8 years ago

Doesn't work for me. I'm really surprised but this

andreamazz commented 8 years ago

Did you try to profile it?

acegreen commented 8 years ago

Never really played around with instruments or the other tools.

andreamazz commented 8 years ago

Always a good time to start :)
It's pretty easy for basic forensics, pick the time profiler, start recording, trigger the segue and stop the recording. Then you can drill down in the list of calls to see which one takes the most time.

acegreen commented 8 years ago

Just took a shot at it. every time I hit record, my Xcode crashes with thread 1 error

NVM Xcode session shouldn't be running

andreamazz commented 8 years ago

Awesome. Try launching instruments on its own and attach it to the running process on your phone.

acegreen commented 8 years ago

Ok did that and performed the segue and stopped. Now I see stuff I need translated

andreamazz commented 8 years ago

You should see the calls tack with the time it took for each stack. Drill down and check which func takes the most percentage.

acegreen commented 8 years ago

Ok I see 73% on the main thread

screen shot 2015-12-09 at 10 45 22 am
andreamazz commented 8 years ago

Keep opening the disclosure triangle until you reach a func call that you can recognize (either from UIKit or your code)

acegreen commented 8 years ago

Ah this is just not for me. I rather go at it the old fashion way.

Do you happen to have 5 minutes to Skype?

I can't read through this at all

Chronic_segue_analysis.trace.zip

acegreen commented 8 years ago

@andreamazz

Ahh I knew it was going to be something super trivial. So as mentioned, I took some stuff from another project and forgot one small thing. In my VC I'm using a custom font that I didnt have as a system font or in my project bundle.

So it seems its an Apple glitch because it resorts to System font but takes longer on first segue. Adding the fonts to the bundle, solves the issue.

andreamazz commented 8 years ago

Good to know :+1: