animateWithDuration: corrupts smooth progressbar increment
Asked Answered
C

2

7

In one of my views i need to animate frame property of a UIImageView and while doing it i want to show a progress bar(UIProgressView) in the title view of the navigation bar.The problem is the if i comment out the following animation blocks the progress bar is updated as expected smoothly.On the other hand due to the following animation the progress bar stops in severals places and carries incrementing again.

//add message bubble
[UIView animateWithDuration:0.3
                      delay:0
                    options:UIViewAnimationOptionAllowUserInteraction
                  animations:^
 {
     animationBubbleImageView.alpha = 1;
 }
                 completion:^(BOOL finished)
 {
     [self removeAutoCorrectionAndHighlight];
     [UIView animateWithDuration:0.3
                           delay:0
                         options:UIViewAnimationOptionAllowUserInteraction
                      animations:^
      {
          CGRect bubbleFrame = CGRectMake(animationBubbleImageView.frame.origin.x,
                                          animationBubbleImageView.frame.origin.y,
                                          bubbleSize.width,
                                          bubbleSize.height);

          [animationBubbleImageView setFrame:bubbleFrame];
          messageLabel.alpha = 1;
      }
                      completion:^(BOOL finished)
      {
          [self sendSubviewToBack:textView];
          [self.delegate moveBubbleToTableCell];
      }];
 }];

animation blocks do not block the main thread but what coudl be the reason of unsmooth beahviout of th progress view ?

UPDATE: What i want to achive is the MessagesApp bubble animation in IOS.While the typed message becomes a bubble and flies to its place the progress bar should increment slowly.

If i try the same thing withou animation progressbar increments normal.

Canaveral answered 28/1, 2013 at 14:59 Comment(5)
Just a wild guess, reason may be that you are updating UI not from the main thread.Interurban
Another wild guess, but have you checked that none of your code in the 3 methods you call from inside this code blocks the main thread?Soracco
And just trying to rule everything out here, but I usually use actual floats in my animation code, i.e. 0.0f as opposed to 0.Soracco
What are you doing in the methods whose implementation we cannot see? Can you try commenting out methods, one by one, and seeing if the animation gets smooth again with certain lines removed?Caesarean
Also, if you're experimenting, I'd see if removing the UIViewAnimationOptionAllowUserInteraction option, or lengthening the animation duration (0.3) helps.Caesarean
N
1

Try putting the progress bar animation in the same animation as the bubble animation. Or put them all into an animation group.

Neglect answered 7/2, 2013 at 13:22 Comment(1)
Actually it is not possible in this case because the animation is split into two parts.The first part is the generation of the bubble and the progress bar should start incrementing there.When the bubble is ready then it triggers the second animation over the delegate method.IF i had all the code in the same class it would like the way you advisedCanaveral
R
-1

Have you tried Instruments to see what's happening?

Wild guess: you can also check whether the two views inadvertently overlap.

If feasible you can also try to group together the animations, as suggested by "Dad".

Best, Akos

Revolting answered 12/2, 2013 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.