0

I am new at xcode and I am learning something new each day, I have gotten stuck. I want to create a custom button on a second Storyboard (MapTwoViewController), lets say it is a custom button that looks like a cloud and it goes from left to right.

I have created the custom button in the storyboard and I have created the IBOutlet in the GWSMapTwoViewController.h so it looks like this and is linked to the button:

#import <UIKit/UIKit.h>

@interface GWSMapTwoViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIButton *cloudAnimate;

@end

So in my GWSMapTwoViewController.m in my view did load I have the following:

#import "GWSMapTwoViewController.h"

@interface GWSMapTwoViewController ()

@end

@implementation GWSMapTwoViewController
@synthesize cloudAnimate;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Move UIView

    cloudAnimate.center = CGPointMake(200.0, 100.0);

    [UIView animateWithDuration:2.0 animations:^{ cloudAnimate.center = CGPointMake(100.0, 200.0);}];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

It just doesn't want to animate, it just goes straight to the end point, if I remove the animation code then the cloud appears at 200, 100 but if I put the animate code in it just moves to 100, 200 or whatever coordinates i put in. It just doesn't animate so its either in the starting point or the end point.

Can anyone tell when what i am doing wrong?

3
  • Your code works perfectly for me. What version of xCode / iOS are you using and targeting ? Dec 6, 2013 at 15:32
  • 5.0.2 what Dimentar said below worked!
    – Dan Davies
    Dec 6, 2013 at 15:43
  • Ok good - must be a difference between simulator and device - the above code works on the simulator for some reason :D Dec 6, 2013 at 15:46

1 Answer 1

3

Move your animation code in

 - (void)viewDidAppear:(BOOL)animated

because viewDidLoad is called before the view is visible.

Don't forget to call super

3
  • His code works for me exactly as it is - I think there is something else he is doing that's causing the problem. Dec 6, 2013 at 15:38
  • 1
    - (void)viewDidLoad is fore Initialization , not for animation
    – Dimentar
    Dec 6, 2013 at 15:40
  • OK it would be good if I could get to the bottom of why it is working for others and not for me but what Dimentar said worked. Hmmm
    – Dan Davies
    Dec 6, 2013 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.