首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SubClass中的UIView动画

SubClass中的UIView动画
EN

Stack Overflow用户
提问于 2014-08-07 22:42:12
回答 1查看 127关注 0票数 0

有谁知道为什么这不管用吗?

UIView子类代码

代码语言:javascript
复制
@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;
                     }];
}

查看控制器代码:

代码语言:javascript
复制
    SendMessageTutorial *sendMessageTutorial = [[SendMessageTutorial alloc] initWithFrame:frame];
    [self.view addSubview:sendMessageTutorial];
    [sendMessageTutorial animateDot];

由于发生了完成块,所以它会隐藏图像视图,但不会使图像视图具有动画效果。

以下是日志的结果:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-08-07 23:26:37

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

代码语言:javascript
复制
[self animateDot]

drawRect内部:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25185421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档