我通過繼承UIPopoverBackgroundView(使用本tutorial),並通過使用UIPopoverController提出它製作自酥料餅。不幸的是,只要我指定自定義popoverBackgroundViewClass本地灰色背景消失。使用自定義UIPopoverBackgroundView時,有什麼方法可以離開黯淡的背景嗎?我可以用來模擬原生行爲的任何其他解決方案?如何暗淡的背景添加到自定義UIPopoverBackgroundView
5
A
回答
4
不知道爲什麼這下來了投票,這是一個很好的問題,因爲當你實現一個自定義UIPopoverBackgroundView,暗淡的背景下不被設置。在研究這個問題時,我確定了最好的方法就是自己設置!
剛剛創建酥料餅的觀點之前,我創建了一個「面具視圖」,將被添加到酥料餅的前視圖。此代碼包括實際上是一個不錯的漸漸以及:
self.customPopoverMaskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.customPopoverMaskView.backgroundColor = [UIColor blackColor];
self.customPopoverMaskView.alpha = 0.3f;
[UIView transitionWithView:self.view
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.view addSubview:self.customPopoverMaskView];
}
completion:nil];
,並刪除視圖,插入該成處理酥料餅的視圖消失的方法(S):
[UIView transitionWithView:self.view
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.customPopoverMaskView removeFromSuperview];
}
completion:nil];
很適合我。快樂的編碼!
亞倫
5
所有你需要的是接下來的代碼添加到initWithFrame:方法你實現UIPopoverBackgroundView的方法。
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0 - self.frame.origin.x,
0 - self.frame.origin.y,
[UIScreen mainScreen].bounds.size.width,
[UIScreen mainScreen].bounds.size.height)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.15;
dimView.userInteractionEnabled = NO;
[self addSubview:dimView];
它的工作原理與默認的Apple實現相同。
相關問題
- 1. 添加的UIView在暗淡的背景
- 2. 背景暗淡不正常
- 3. 如何將自定義背景添加到UISearchDisplayController的表視圖?
- 4. Xamarin.iOS - 自定義UIPopoverBackgroundView
- 5. 如何調暗自定義佈局的背景?
- 6. 如何將背景線程添加到Silverlight自定義控件?
- 7. 視頻播放時暗淡的背景
- 8. 暗淡進度條的背景
- 9. 活動中暗淡或模糊背景
- 10. 暗淡/模糊父佈局背景
- 11. 如何自定義的複選框,添加背景圖片
- 12. 添加光滑的淡入/淡出過渡到背景圖片
- 13. 如何在Autodesk forge中添加自定義背景?
- 14. 如何爲自定義UIToolBar添加背景圖像
- 15. 將自定義背景添加到AlertDialog按鈕
- 16. 將自定義背景添加到D3.js條形圖
- 17. 如何將淡入淡出效果添加到jquery css背景圖片
- 18. 自定義背景
- 19. 自定義背景?
- 20. 添加文本時淡化div背景
- 21. 禁用操作欄的默認背景並添加自定義背景
- 22. 的JPanel自定義背景
- 23. 添加背景的淡入淡出效果改變使用jQuery
- 24. 在jQuery滑塊的背景圖像上添加淡入淡出
- 25. 如何淡化背景
- 26. THREE.js - 如何淡入淡出背景?
- 27. 如何在顯示自定義視圖時調暗背景視圖
- 28. 中添加自定義背景圖片的WordPress一次
- 29. 如何在頁面加載的背景下淡入淡出-jQuery
- 30. 如何給黑暗的背景比原始背景的div?
請把你的代碼在這裏 – malex
我更新了我的問題。我添加了我正在使用的教程的鏈接。 – sash
不明白,爲什麼要投下來的問題?這不是關於如何繼承UIPopoverBackgroundView或者爲什麼它不工作。現在的問題是:是否有可能設置暗淡的背景開箱即用,如果你繼承UIPopoverBackgroundView。 – sash