2013-04-01 23 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

相關問題