2013-07-17 43 views
1

我開發了一個利用UIPickerView和UIToolbar的字體選擇,它們都是在觸摸UIButton時添加的。如何爲我的子視圖添加動畫?

但他們只是一種流行在其中看起來馬虎。

有沒有辦法讓它們動起來?

這裏是增加了他們(這就是所謂的點擊按鈕)的方法:

-(void)showPicker 
{ 
    [self.view addSubview:_fontPicker]; 
    [self.view addSubview:pickerTB]; 

} 

回答

2

您可以在幾個方面它們的動畫,但可能是最簡單的就是剛剛褪去他們

淡入

[someView setAlpha:0] 
[self.view addSubview:someView]; 
[UIView beginAnimations:@"FadeIn" context:nil]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[someView setAlpha:1]; 
[UIView commitAnimations]; 

淡出

float fadeDuration = 0.5; 
[UIView beginAnimations:@"FadeOut" context:nil]; 
[UIView setAnimationDuration:fadeDuration ]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[someView setAlpha:0]; 
[UIView setAnimationDidStopSelector:@selector(removeView)]; 
[UIView commitAnimations]; 


-(void) removeView { 
    [someView removeFromSuperview]; 
} 

就這麼簡單。

+0

我將如何扭轉這種褪色的意見呢? – Exothug

+0

您只需將alpha值更改爲0,以便淡出。 '[someView setAlpha:0]'裏面的動畫構造 – MZimmerman6

+0

謝謝。你真棒。 – Exothug

0

取決於你想使用什麼類型的動畫。例如,這看起來像解散。 反正看着UIView animateWithDuration...

pickerTB.alpha = _fontPicker.alpha = 0; 
[self.view addSubview:_fontPicker]; 
[self.view addSubview:pickerTB]; 
[UIView animateWithDuration:1 animations:^{_fontPicker.alpha = 1; pickerTB.alpha = 1}]; 

你可以使用轉換或更改框架的起源作出的意見,從崗位飛在屏幕外面了。在這種情況下,在動畫塊內,指定新的屏幕位置。你可以通過兩種方式做到這一點,改變框架與更新的原點或應用CGAffineTransformMakeTranslation(dx,dy)

0

你需要添加一個框架值,你想動畫開始(屏幕外?)的子視圖,然後更改動畫塊內的幀值。框架會在整個持續時間內發生變化,導致運動的出現。該視圖必須已經是一個子視圖 - 我不認爲添加子視圖是可以進行動畫製作的,這是沒有意義的。

- (無效)showPicker {

[self.view addSubview: _fontPicker]; 
_fontPicker.frame = CGRectMake(0, 0, 120, 40);// somewhere offscreen, in the direction you want it to appear from 
[UIView animateWithDuration:10.0 
       animations:^{ 
        geopointView.frame = // its final location 
       }]; 
} 
0

最初設置你的選擇器視圖框和工具欄架像這樣的..

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    pickerTB.frame = CGRectMake(0,568,320,44); 
    fontPicker.frame = CGRectMake(0, 568, 320, 216); 
} 

-(void)showPicker 
{ 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:.30]; 
     if(isiPhone5) 
     { 
      pickerTB.frame = CGRectMake(0,288,320,44); 
      fontPicker.frame = CGRectMake(0, 332, 320, 216); 
     }else{ 

     pickerTB.frame = CGRectMake(0,200,320,44); 
     fontPicker.frame = CGRectMake(0,244, 320, 216); 
     } 
    [UIView commitAnimations]; 
} 
相關問題