2013-01-31 20 views
0

我不知道如何處理動畫,我希望在半透明視圖中淡入淡出,並在Tumblr應用程序如何爲其撰寫屏幕輕觸背景時解除它。我如何淡入半透明的UIVIew中,並在bg被觸摸時解散?

這是我到目前爲止。它增加了半透明的觀點,但並沒有像Tumblr那樣褪色。

UIView *modalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[modalView setOpaque: NO]; 
[modalView setBackgroundColor: [UIColor colorWithAlphaComponent: 0.9]; 
[[self view] addSubview: modalView]; 
+0

你想顯示的模型圖?你是否使用多個視圖控制器來完成這項工作? –

+0

@RandyMarsh是的,即時通訊嘗試顯示模式視圖,但與透明度,所以我仍然可以看到視圖控制器類似於tumblr應用程序 – James2303

+0

爲什麼你添加'modalView'到視圖控制器的視圖?如果'modalView'是你的模態視圖,則使用一個視圖控制器來管理'modalView'並使用'presentViewController:animated:completion:'。在模態視圖控制器上,預先使用'-setTransitionStyle:'將過渡樣式設置爲'UIModalTransitionStyleCrossDissolve'。 –

回答

1

我不知道你想實現什麼,但它看起來像你需要UIView動畫和UITapGestureRecognizer

使用此代碼的組合在視圖中淡出(適當調整的開始和結束α值) :

[modalView setAlpha:0]; 
[UIView animateWithDuration:0.5f 
         delay:0.0f 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^(void) { 
        [myView setAlpha:1.0; 
       } 
       completion:NULL]; 

這創造手勢識別:

UITapGestureRecognizer *tapgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapView)]; 
tapgr.cancelsTouchesInView = NO; 
[timeView addGestureRecognizer:tapgr]; 

didTapView是你的方法來解除視圖。

希望這會有所幫助。

+0

aww男人感謝這對我完美的作品淡入淡出時,我如何反轉動畫淡出? – James2303

+0

使用相同的代碼,但將動畫塊中的alpha設置爲0. –

+0

感謝工作完美...現在,我添加視圖到超級視圖淡出時它是從超級視圖中刪除?或者我需要在我的didTapview手勢中調用它? – James2303

0

您是否嘗試在此半透明視圖中添加水龍頭識別器?見UITapGestureRecognizer class

+0

還沒有過去在我的當前視圖的半透明視圖動畫的第一部分 – James2303

0

如果我理解正確,你的問題是沒有動畫。動畫很簡單:

UIView *modalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[modalView setOpaque: NO]; 
[modalView setBackgroundColor: [UIColor colorWithAlphaComponent: 0.9]; 
[[self view] addSubview: modalView]; 

[modalView setAlpha: 0]; 
[UIView animateWithDuration: 0.5 animations: ^{ 
    [modalView setAlpha: 1]; 
} 

探索UIView的完成處理其他動畫方法等

+0

謝謝你這個作品完美即時試着想要如何淡出現在爲解散視圖 – James2303