Kiran Bhoraniya
Kiran Bhoraniya

Reputation: 103

Move object from bottom to top

I’ve an image of arrow, i want to fly that image from bottom to top.I've research on that but can not find the proper solution.

self.View.frame = CGRectMake(0, 490, 320, 460);

For the animation from bottom to top add below:

[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];

I've used this code, but its not fulfill my requirement.

I want to fly the arrow like this : link

Thanks.

Upvotes: 0

Views: 288

Answers (3)

Daniel Storm
Daniel Storm

Reputation: 18898

You need to add your subView to your view before you try to animate it. For example:

// 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){
}];

Also, names that start with capital letters are reserved for classes. Rename View. Perhaps to myView, viewToAnimate, someRandomView, etc...

Upvotes: 0

KSR
KSR

Reputation: 1709

I made a sample animation for your requirement.

#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

enter image description here

enter image description here

Please use the following link of my GitHub link, to test sample:

https://github.com/k-sathireddy/ArrowAnimation

Please make the animation smooth.

Upvotes: 1

SBK
SBK

Reputation: 101

Your Code Run Fine :

[self.view addSubview:self.View]; 

This Line Put Before Animation Code

Upvotes: 0

Related Questions