gpt4 book ai didi

ios - 动画 Logo 从中心点向左向右移动

转载 作者:行者123 更新时间:2023-11-29 02:42:54 24 4
gpt4 key购买 nike

在使用 UIView 动画时,我绝对是个初学者。我需要做的就是将 imageView 从起始位置向右移动 40 点,并将位置从初始位置向左移动 40 点。这应该不断重复......

- (void)animateLogo
{
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^{
CGRect frame = CGRectMake(self.Logo.frame.origin.y, 10.0, self.Logo.frame.size.width, self.Logo.frame.size.height);
self.Logo.frame = frame;
}
completion:nil];
}

所有这一切只是将它向上向下移动而不是向左向右移动。我尝试将 X 参数设置为 10 但没有改变....我该怎么做?

最佳答案

工作代码:

//note that this rect has x = 0
// you don't have to set this startRect if you created your logo in storyboard
CGRect startRect = CGRectMake(0, 0, 300, 300);
[self.Logo setFrame:startRect];

[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^{
//note that this x is +40
CGRect frame = CGRectMake(self.Logo.frame.origin.x + 40, self.Logo.frame.origin.y, self.Logo.frame.size.width, self.Logo.frame.size.height);
self.Logo.frame = frame;
}
completion:^(BOOL finished) {
}];

更新

假设您的 Logo 是一个 UIImageView,尝试以编程方式创建 Logo :

CGRect startRect = CGRectMake(318, 47, 133, 97);
UIImageView *LogoImage = [[UIImageView alloc] initWithFrame:startRect];
[LogoImage setImage:[UIImage imageNamed:@"unselected_image.png"]];
[LogoImage setBackgroundColor:[UIColor redColor]];

[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^{
//note that this x is +40
CGRect frame = CGRectMake(LogoImage.frame.origin.x + 40, LogoImage.frame.origin.y, LogoImage.frame.size.width, LogoImage.frame.size.height);
LogoImage.frame = frame;
}
completion:nil];

[self.view addSubview:LogoImage];

关于ios - 动画 Logo 从中心点向左向右移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25536061/

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