我希望在视图加载时倒计时图像。为此目的,我在视图加载时延迟了所有函数。在视图加载时我做了
- (void)viewDidLoad
{
//-=-=-=-=-=-=-=-=-=-=-=-=-=Count Down Numbers animation-=-=-=-=-=-=-=-=-=-
NumImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"03.png"], [UIImage imageNamed:@"02.png"],[UIImage imageNamed:@"01.png"], nil];
NumImageView.animationDuration =4;
[numView addSubview:NumImageView];
[NumImageView startAnimating];
.......//remaining code
}
这里我在numView上删除了NumImageView UIImageView
。
但未获取所有图像.3和1动画显示剩余的2张图像。实际上这是正确的过程或使用NSThread
是正确的过程,但我现在不知道如何使用NSThread
。
答案 0 :(得分:0)
你可能想做这样的事情,我不知道你的实施细节,但我相信你可以搞清楚
//add all images into an array with
NSArray *NumImageView = @{img1, img2, img3, img4}; //these are UIImageViews that you have made previously
for(int i = 0; i < NumImageView.count; i++){
[numView addSubview:NumImageView[i]]; //add all images
NumImageView[i].hidden = true; //make them hidden initially
}
for(int i = 0; i < NumImageView.count; i++){
[UIView animateWithDuration:1.0 delay:i*1.0 options:UIViewAnimationOptionCurveLinear animations:^{
NumImageView[i].hidden = false; //unhide when it starts aniamting
//animate image coming in
} completion:^(BOOL finished) {
UIImageView *image = NumImageView[i];
[image removeFromSuperView]; //remove current number
}];
}
答案 1 :(得分:0)
你也可以通过动画块实现这一点,动画块在达到完成时移动到下一个动画,就像在这个方法中一样:
- (void)animateCountDown
{
//first add numImageView
[numView addSubview:numImageView];
//add first image
numImageView.image = [UIImage imageNamed:@"03.png"];
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^
{
numImageView.image = [UIImage imageNamed:@"02.png"];
}
completion:^(BOOL finished)
{
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^
{
numImageView.image = [UIImage imageNamed:@"01.png"];
}
completion:^(BOOL finished)
{
//start whatever after countdown
}];
}];
}
然后在您的viewDidLoad
中调用此内容[self animateCountDown];
另一种方法是使用NSTimer
。我做了一个例子,你可以看到如何使用你认为合适的。在此示例中,NSTimer
正在调用countMethod
,这会将count integer
递减,将UIImage
设置为UIImageView
,countMethod
也会检查count integer
如果invalidate
低于1,那么可以NSTimer
{{1}},并且您可以调用方法来启动应用程序的其余部分。
听起来很多,但是看一下这个截图,一切都很清楚:
答案 2 :(得分:0)
试试这个
-(void)viewdidload
{
[NSThread detachNewThreadSelector:@selector(animateImages) toTarget:self withObject:nil]
}
-(void)animateImages
{
//-=-=-=-=-=-=-=-=-=-=-=-=-=Count Down Numbers animation-=-=-=-=-=-=-=-=-=-
NumImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"03.png"], [UIImage imageNamed:@"02.png"],[UIImage imageNamed:@"01.png"], nil];
NumImageView.animationDuration =4;
// repeat the annimation forever
NumImageView.animationRepeatCount = 1;
[NumImageView startAnimating];
[numView addSubview:NumImageView];
.......//remaining code
}