SubClass中的UIView动画

时间:2014-08-07 14:42:12

标签: ios uiview uiviewanimation

任何人都知道为什么这不起作用?

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

1 个答案:

答案 0 :(得分:0)

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

[self animateDot]

里面的drawRect: