在NSmutableArray中更新UIImageView的图像?

时间:2015-06-28 04:15:08

标签: objective-c uiimageview

我有:

Class Piece继承UIImageView;

- (void)setJumpAt:(int)frame {
NSMutableArray *ret = [SkinConstants BallSelected];
NSString *name = [NSString stringWithFormat:@"balls-%d-%d", color - 1, [[ret objectAtIndex:frame] intValue]];
UIImage *a = [UIImage imageNamed:name];
NSLog(@"%d setJumpAt: %@", self.tag ,name);
[self performSelectorOnMainThread:@selector(setImage:) withObject:a waitUntilDone:NO];
[self  setNeedsDisplay];
[self setNeedsLayout];}

Class Player包含Piece的NSMutableArray;

类JumpThread包含NSTimer用于设置Piece的图像;

- (void) timer_Tick{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
        [piece setJumpAt:frame++];
        [piece setNeedsDisplay];
        if (frame == len)
            frame = 0;
    dispatch_async(dispatch_get_main_queue(), ^{
    });
});}

我运行代码正常,但是在主视图中,Piece的图像没有变化, 对不起,我的英语不太好。

1 个答案:

答案 0 :(得分:0)

UIImageView可以使用一组UIImages和合适的animationDuration

为图像设置动画
//self is an UIImageView instance
NSArray images = [...]; // your frames
self.animationImages = images;
self.animationDuration = 2.0f // 2.0s
[self startAnimating];