0

Anyone have any idea why this isn't working?

UIView Subclass Code

@implementation SendMessageTutorial
@synthesize animatedDot;
@synthesize titleLabel;
@synthesize isDrawn;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SendMessageTutorial" owner:self options:NULL];
        self = (SendMessageTutorial *)[nib objectAtIndex:0];

        self.titleLabel = [self.subviews objectAtIndex:1];
        self.animatedDot = [self.subviews objectAtIndex:2];

        self.opaque = NO;

        self.isDrawn = NO;
    }
    return self;
}

- (void) animateDot
{
    CGRect movedFrame = self.animatedDot.frame;
    movedFrame.origin.y = 300;//self.frame.size.height - self.animatedDot.frame.size.height - 20;
    NSLog(@"position %f", self.animatedDot.frame.origin.y);

    [UIView animateWithDuration:0.7f
                     animations:^{
                         NSLog(@"position %f", self.animatedDot.frame.origin.y);
                         self.animatedDot.frame = movedFrame;
                         NSLog(@"position %f", self.animatedDot.frame.origin.y);
                     }
                     completion:^(BOOL finished){
                         NSLog(@"completion block");
                         self.animatedDot.hidden = YES;
                     }];
}

View Controller Code:

    SendMessageTutorial *sendMessageTutorial = [[SendMessageTutorial alloc] initWithFrame:frame];
    [self.view addSubview:sendMessageTutorial];
    [sendMessageTutorial animateDot];

The completion block happens, so it hides the imageview but it doesn't animate the imageview.

Here are the results from the log:

2014-08-07 10:54:52.186 [7280:90b] position 250.000000
2014-08-07 10:54:52.186 [7280:90b] position 250.000000
2014-08-07 10:54:52.186 [7280:90b] position 300.000000
2014-08-07 10:54:52.888 [7280:90b] completion block
Mikerizzo
  • 587
  • 1
  • 4
  • 22
  • **1st**: in your case would be more efficient to animate the `center` only instead of the `frame`. **2nd**: there is no information about the _before_ and _after_ values, so that is hard to tell – you might not animate anything if those values are the same... – holex Aug 07 '14 at 14:54
  • This is what the logs print out: 2014-08-07 10:54:52.186 [7280:90b] position 250.000000 2014-08-07 10:54:52.186 [7280:90b] position 250.000000 2014-08-07 10:54:52.186 [7280:90b] position 300.000000 2014-08-07 10:54:52.888 [7280:90b] completion block – Mikerizzo Aug 07 '14 at 14:55
  • you may need to add that information to your original question, perhaps... – holex Aug 07 '14 at 14:56

1 Answers1

0

I solved the problem. I had to call

[self animateDot]

inside drawRect:

Mikerizzo
  • 587
  • 1
  • 4
  • 22