0
votes

I have a custom view (which draws callouts/bubbles) that I currently add as a subview to a UIImageView. It works as intended but I would like to animate the operation with a spring-like effect. I am using the below code but it does not work (the block gets executed but without animation):

/* ViewController */    

UIImageView *iv = self.imageView;

ZGCBubbleView *bubbleView = [[ZGCBubbleView alloc] init];
bubbleView.hidden = YES;
[iv addSubview:bubbleView];

// UIView animation test
[UIView animateWithDuration:2.0
                      delay:0
     usingSpringWithDamping:0.5
      initialSpringVelocity:0.5
                    options:UIViewAnimationOptionAllowAnimatedContent & UIViewAnimationOptionLayoutSubviews
                 animations:^{

                     bubbleView.hidden = NO;
                     [self.view layoutIfNeeded]; // tried this
                 }
                 completion:nil];

I have tried to animate both the hidden property as well as the alpha properties but same result. I have also tried animating the addSubview method, no difference. I started out with a more simple animation as proof of concept but that didn't work either.

The above code is executed within a method which is called during the (void)viewDidAppear:(BOOL)animated cycle. Does this have anything to do with this in that the animation is being executed during the main thread? I have read something to that effect but unsure. Also, I am using auto layout for the UIImageView but didn't think that would matter in this case since the animation is being applied to a custom subview of the UIImageView.

Any help appreciated.

2
Are you trying to fade in the view? Is the fading being animated as desired? Or are you trying to animate some other aspect?rmaddy

2 Answers

0
votes

Try with this.

UIButton *catchButton = (UIButton *)sender;

[UIView animateWithDuration:1.0 
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseInOut//UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat |
                 animations:^{
                     catchButton.alpha = 0.4;
                     catchButton.enabled = NO;
                 }
                 completion:NULL];
0
votes

Better use alpha.

UIImageView *iv = self.imageView;

ZGCBubbleView *bubbleView = [[ZGCBubbleView alloc] init];
bubbleView.alpha = 0;
// bubbleView.hidden = YES;
[iv addSubview:bubbleView];

// UIView animation test
[UIView animateWithDuration:2.0
                  delay:0
 usingSpringWithDamping:0.5
  initialSpringVelocity:0.5
                options:UIViewAnimationOptionAllowAnimatedContent & UIViewAnimationOptionLayoutSubviews
             animations:^{
                // bubbleView.hidden = NO;
                 bubbleView.alpha = 1;
                 //[self.view layoutIfNeeded]; // tried this
             }
             completion:nil];