子类中的UIView动画



有人知道为什么这不起作用吗?

UIView子类代码

@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;
                     }];
}

视图控制器代码:

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

完成块发生了,所以它隐藏了imageview,但它没有使imageview动画化。

以下是日志的结果:

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

我解决了这个问题。我不得不打电话给

[self animateDot]
绘制矩形内

:

最新更新