【问题标题】:Move object from bottom to top从下到上移动对象
【发布时间】:2016-09-16 20:55:14
【问题描述】:

我有一个箭头图像,我想从下到上飞行该图像。我对此进行了研究,但找不到合适的解决方案。

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

谢谢。

【问题讨论】:

标签: ios iphone


【解决方案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

请让动画流畅。

【讨论】:

    【解决方案2】:

    您的代码运行良好:

    [self.view addSubview:self.View]; 
    

    这一行放在动画代码之前

    【讨论】:

      【解决方案3】:

      您需要将您的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。也许是myViewviewToAnimatesomeRandomView等……

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-30
        • 1970-01-01
        • 1970-01-01
        • 2015-03-23
        • 2017-11-07
        相关资源
        最近更新 更多