我有一张箭头的图像,我想从下到上飞过那个图像。我对此进行了研究,但找不到合适的解决方案。
self.View.frame = CGRectMake(0, 490, 320, 460);
对于从下到上的动画添加如下:
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseIn
animations:^{
self.View.frame = CGRectMake(0, 0, 320, 460);
}
completion:^(BOOL finished){
}];
[self.view addSubview:self.View];
我已经使用过此代码,但它不符合我的要求。
我想像这样飞过箭头:link
感谢。
答案 0 :(得分:1)
我根据您的要求制作了一个动画示例。
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *arrowImageView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *arrowLeadingSpaceConstraint;
- (IBAction)goButtonTapped:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
float degrees = 270; //the value in degrees
self.arrowImageView.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
}
- (IBAction)goButtonTapped:(id)sender {
// self.arrowLeadingSpaceConstraint.constant = 310;
self.arrowImageView.frame = CGRectMake(310, 574, 20, 30);
float degrees = 270; //the value in degrees
self.arrowImageView.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
[UIView animateWithDuration:0.2
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
self.arrowImageView.frame = CGRectMake(100, 574, 20, 30);
self.arrowImageView.transform = CGAffineTransformMakeRotation(0 * M_PI/180);
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.2
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
self.arrowImageView.frame = CGRectMake(50, 150, 20, 30);
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.1
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
self.arrowImageView.frame = CGRectMake(80, 100, 20, 30);
}
completion:nil];
}];
}];
}
@end
请使用我的GitHub链接的以下链接来测试样本:
https://github.com/k-sathireddy/ArrowAnimation
请让动画流畅。
答案 1 :(得分:0)
您的代码运行良好:
[self.view addSubview:self.View];
此行放入动画代码
答案 2 :(得分:0)
您需要先将subView
添加到view
之前,然后再尝试为其设置动画。例如:
// Add subview
[self.view addSubview:self.myView];
// Now animate it
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseIn
animations:^{
self.myView.frame = CGRectMake(0, 0, 320, 460);
}
completion:^(BOOL finished){
}];
此外,以大写字母开头的名称是为类保留的。重命名View
。也许是myView
,viewToAnimate
,someRandomView
等......