0

Im creating a custom view, it contains methods like Refresh,*LayoutSubviews*, following this tutorial

I want a label to be animated growing, to it's full width and then back to 0 width. Im using this code in "refresh" method:

[UIView animateWithDuration:1.3 animations:^{
        CGRect frame = CGRectMake(50, 15, 140, 20);
        [labelFav setFrame:frame];
    } completion:^(BOOL finished) {
        //[labelFav setHidden:YES];
        [UIView animateWithDuration:1.3 animations:^{
            CGRect frame = CGRectMake(50, 15, 0, 20);
            [labelFav setFrame:frame];
        }];

    }];

The code works on any other view, but since this is a Custom view by some reason the completion block is not executing. What happens is that it only does the first block. I set a breakpoint in the "completion" block and it stops there but the animation doesnt happen. I tried to setHidden the label and still it doesnt happen.

Any ideas?

subharb
  • 3,374
  • 8
  • 41
  • 72

2 Answers2

0

Another way to solve problem. Tested.

[UIView animateWithDuration:1.3 animations:^{

    CGRect frame = CGRectMake(50, 15, 140, 20);
    [labelViewForFav setFrame:frame];

} completion:^(BOOL finished) {

   [UIView animateWithDuration:1.3 animations:^{

                CGRect frame = CGRectMake(50, 15, 0, 20);
                [labelViewForFav setFrame:frame];

        } completion:^(BOOL finished) {

        }];
}];

Problem is When you make UIlabel width less than its current width. Animation is not done properly. Animation not visible just jump to final frame.

to solve it Put your label in a view change the size of this view and it will work properly.

mialkan
  • 342
  • 3
  • 7
  • yes I did. The first animation happens correctly, is the one that should start right after the first one finishes that isnt happening. – subharb Oct 08 '13 at 14:26
  • I wrote a code I hope this works properly. Let me know the result. – mialkan Oct 08 '13 at 15:07
  • Sorry it doesnt, it happens the same thing as my code. The first animation happens, but the one that should happen after the first one doesnt. Try to use this in a Custom view in the Refresh Method. It would work on any other view, but this has to happen in the refresh method of a custom view. thanks for trying though. – subharb Oct 09 '13 at 11:48
  • I think shirink not working coz of the anchor point. When you expand your UIlabel with anition it works. and your second animation jumps to comclusion I will find another way for you – mialkan Oct 09 '13 at 12:18
  • I found another way my friend hope its ok for you? – mialkan Oct 09 '13 at 12:27
  • Im afraid is still not working. You have to test it in a Custom View, in the refresh method. For some reason it only does the first part of the animation, no matter how you set the methods. – subharb Oct 10 '13 at 15:01
  • Here is example code I check it its working. [Example Custom View](https://www.dropbox.com/s/ggs2ns6snj70nxb/CustomView.zip) – mialkan Oct 10 '13 at 15:26
  • I am actually using that same article to create this, but if you put try to animate that it wont work. – subharb Oct 14 '13 at 11:06
0

remove auto layout from you Interface builder main screen. your view may be changing it's frame, but auto layout is (possibly) forcing it elsewhere...

chewy
  • 8,207
  • 6
  • 42
  • 70