![](/img/trans.png)
[英]How to automatically change transparent color of a view based on the color of it’s background
[英]How to disable background view with dark transparent color?
我為從屏幕底部滑動的uiview創建了動畫,但是我希望在視圖滑動到屏幕上以禁用bg視圖並使用這樣的暗bg:
我怎樣才能做到這一點? 此外,當我點擊暗透明視圖時,我希望它滑出並啟用bg視圖。
這是我如何做滑動動畫:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
} else if (buttonIndex == 1) {
self.slidingView.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.slidingView.frame = CGRectMake(0,0,320,20);
self.view.frame = CGRectMake(0,0,320,460);
[UIView commitAnimations];
self.view.userInteractionEnabled = NO;
}
}
Thanksss
我在最近的一個項目上做了類似的事情。 不是僅添加一個包含選擇器的視圖的視圖,而是向其添加父視圖。 因此,您將添加到視圖控制器的視圖將是具有透明黑色背景的屏幕大小,然后使用您的自定義動畫選擇器將視圖添加到子視圖。
另一種方法是在視圖控制器中創建一個最初隱藏的視圖,並在顯示您的選擇器視圖時顯示它。
如果您可以分享您的代碼,我可以更好地幫助您。
編輯:
- 在視圖控制器中添加具有相同寬度和高度的視圖,具有前導,頂部,尾部和底部約束。
- 有這個視圖的出口(例如:backgroundView)
-in viewDidLoad:
添加以下行:
self.backgroundView.hidden=YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourcodeToCloseTheView)];
singleTap.numberOfTapsRequired = 1;
[self.backgroundView addGestureRecognizer:singleTap];
- 並在您的actionSheet:clickedButtonAtIndex:
添加以下行:
self.backgroundView.hidden=NO;
只需確保backgroundView位於IB中的pickerView后面。
希望有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.