2013-04-01 24 views
-1

我有一个名为logoview的UIView。UIView animateWithDuration结果每次都在同一位置

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


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

我正在尝试使用上面的代码对它进行设置。它会导致对象每次都从头到尾转向中心。无论我在动画部分中使用哪些线,我都使用故事板。

我的最终目标是简单地在中心显示徽标。然后像在Skype上一样提升徽标,并在Facebook登录中显示登录字段。然而,不管我输入什么值

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

它只是去中心。

我也只是尝试:

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


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

其工作是解除logoview但同时也抵消了下来很有点...使其成为偏心。

整个.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 

回答

0

像这样的事情?

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

工作..感谢@matt太 – Michael

3

那么,一个问题是,viewDidLoad是太快了。你想等到至少viewDidAppear。您的界面尚未在viewDidLoad中获得实际尺寸。发生的一切就是你的视图控制器的一个视图;该视图在界面中还没有,更不用说对用户可见了。

+0

好吧我做到了这一点...我关掉自动布局,它开始正确动画... – Michael

+0

@Michael你可能会发现在我的书中有关autolayout的讨论很有用:http: //www.apeth.com/iOSBook/ch14.html#_autolayout还有(尤其是)动画和约束之间的战斗:http://www.apeth.com/iOSBook/ch17.html#_animation_and_autolayout基本上我认为这是一个在iOS中实现约束的主要缺陷:您尝试更改视图的框架,并且约束会将其更改回来。 – matt

相关问题