Michael Michael - 2 months ago 12
iOS Question

UIView animateWithDuration results in the same location every time

I have a UIView called logoview.

[logoview setCenter:CGPointMake(100,100)];
[UIView animateWithDuration:4
delay:1
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
[logoview setCenter:CGPointMake(0, 3232)];


}
completion:^(BOOL finished) {
}];


I'm trying to animate it with the above code. It results in the object moving to the center from the topleft corner everytime. No matter what cords I ser in the animation section.... I'm using storyboard.

My end goal is to simply show the logo in the center. Then raise the logo up like on the Skype, and facebook logins revealing the login fields. However no matter what values I put for

[logoview setCenter:CGPointMake(0, 3232)];


It just goes to the center.

I also just tried:

[UIView animateWithDuration:4
delay:1
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
[logoview setTransform: CGAffineTransformMakeTranslation(0, -80)];


}
completion:^(BOOL finished) {
}];


Which works to lift the logoview but it also offsets it down quite bit... Making it offcenter.

Entire .m

//
// ViewController.m
// Couple
//
// Created by Michael Latman on 4/1/13.
// Copyright (c) 2013 Michael Latman. All rights reserved.
//

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
//Rounded corners!
self.view.layer.cornerRadius = 10;
self.view.layer.masksToBounds = YES;
//lol.layer.cornerRadius = 90;
//lol.layer.masksToBounds = YES;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//[logoview setCenter:CGPointMake(100,100)];
[UIView animateWithDuration:4
delay:1
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{

[logoview setCenter:CGPointMake(0, 1)];


}
completion:^(BOOL finished) {
}];


}

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

@end

Answer

Something like this?

[UIView animateWithDuration:4.0 delay:1.0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{
    [logoview setCenter:CGPointMake(logoview.center.x, logoview.center.y - 80.0)];
} completion:nil];