gpt4 book ai didi

ios - 在x轴上创建连续uiimage动画

转载 作者:行者123 更新时间:2023-12-01 17:58:40 24 4
gpt4 key购买 nike

我想创建像http://disqus.com/这样的背景继续使用背景,但是尝试使用这样的代码后却无法获取背景

continuesBackground =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pattern"]];
continuesBackground.frame=CGRectMake(0, 56, 320, 102);
continuesBackground.layer.zPosition=100;
[UIView animateWithDuration:5.0
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
continuesBackground.transform = CGAffineTransformMakeTranslation(0, 200); }
completion:^(BOOL finish) {
continuesBackground.transform = CGAffineTransformMakeTranslation(200, 0);

}];

怎么做?我需要nstimer吗?

最佳答案

尝试这个:

- (void)animateImageViewFromStartPosition:(CGPoint)aStartPosition toEndPosition:(CGPoint)aEndPosition; {
CGRect oldFrame = CGRectMake(aStartPosition.x, aStartPosition.y, continuesBackground.frame.size.width, continuesBackground.frame.size.height);
[continuesBackground setFrame:oldFrame];

[UIView animateWithDuration:5.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^(void){
CGRect newFrame = continuesBackground.frame;
newFrame.origin = aEndPosition;
continuesBackground.frame = newFrame;
}
completion:^(BOOL finished){
if(finished){
[self animateImageViewFromStartPosition:aStartPosition toEndPosition:aEndPosition];
}
}];
}

然后在 viewDidLoad方法中调用该方法:
- (void)viewDidLoad; {
[super viewDidLoad];
[self animateImageViewFromStartPosition:CGPointMake(0.0f, 56.0f) toEndPosition:CGPointMake(320.0f, 56.0f)];
}

您可以轻松地将其修改为变换或任何您想要的形式,它将使动画无限期地进行下去。希望对您有所帮助!

关于ios - 在x轴上创建连续uiimage动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13319601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com