UIView animation does not animate at first try?

Posted by Bacalso Vincent on Stack Overflow See other posts from Stack Overflow or by Bacalso Vincent
Published on 2012-06-29T06:29:09Z Indexed on 2012/06/30 15:16 UTC
Read the original article Hit count: 217

Filed under:
|
|

Considering that my _palette's frame is like this:

_palette.frame = CGRectMake(0,480,320,200);

I have this code here to slide up/down a UIView:

if(![_pallete superview]) {
[self.view addSubview:_pallete];
[self.view insertSubview:_tempViewPaletteListener belowSubview:_pallete];

[UIView animateWithDuration:0.3 
                 animations:^{
                   _pallete.top -= kPaletteHeight;
                 } 
                 completion:^(BOOL isFinished) {

                 }];

 } else {

[UIView animateWithDuration:0.3 
                 animations:^{
                   _pallete.top += kPaletteHeight;
                 } 
                 completion:^(BOOL isFinished) {
                   [_tempViewPaletteListener removeFromSuperview];
                   [_pallete removeFromSuperview];
                 }];
 }

*the _tempViewPaletteListener is just a view with a tap gesture use to dismiss the palette*

The problem is when I first try to run code here, the _palette view will just stiffly display right away. What I expected is, it should slide up the _palette view.

Though it works fine after the first try

© Stack Overflow or respective owner

Related posts about ios

Related posts about uiview