我需要添加一個包含一些按鈕並出現在所有視圖控制器中的視圖。該視圖應該包含一個水平滾動視圖,其中放置所有按鈕。如何在標籤欄底部的所有視圖控制器中添加公共視圖
該視圖需要位於標籤欄之上。類似的圖像The player in the apple music application, on top of the tab bar in the bottom
任何幫助表示讚賞。謝謝!
我需要添加一個包含一些按鈕並出現在所有視圖控制器中的視圖。該視圖應該包含一個水平滾動視圖,其中放置所有按鈕。如何在標籤欄底部的所有視圖控制器中添加公共視圖
該視圖需要位於標籤欄之上。類似的圖像The player in the apple music application, on top of the tab bar in the bottom
任何幫助表示讚賞。謝謝!
試試這個:
這是Swift 3代碼。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
view.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-100, width: UIScreen.main.bounds.width , height: 100)
//window?.willRemoveSubview(view)
//Add ScrollView to View
let scrollview = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
scrollview.contentSize = CGSize(width: view.frame.size.width*2, height: view.frame.size.height)
scrollview.backgroundColor = UIColor.blue
scrollview.removeFromSuperview()
view.addSubview(scrollview)
//Add Button to Scrollview
let btn = UIButton(frame: CGRect(x: scrollview.frame.size.width/3, y: scrollview.frame.size.height/2, width: 50, height: 30))
btn.setTitle("Heloo", for: UIControlState.normal)
btn.setTitleColor(UIColor.red, for: UIControlState.normal)
let btn2 = UIButton(frame: CGRect(x: scrollview.frame.size.width/2, y: scrollview.frame.size.height/2, width: 50, height: 30))
btn2.setTitle("Hiiii", for: UIControlState.normal)
btn2.setTitleColor(UIColor.red, for: UIControlState.normal)
scrollview.addSubview(btn)
scrollview.addSubview(btn2)
window?.makeKeyAndVisible()
window?.insertSubview(view, at: 0)
window?.bringSubview(toFront: view)
return true
}
希望這有助於
如果需要放置視圖,需要在運行的應用程序的所有時間對所有控制器的意見上方顯示,添加subview
到window
在您的應用程序委託。
優點:
缺點是速度快對於行動 的按鈕)
OR:
如果你只需要UITabBar與滾動擴展的能力,更好的是設置的TabBar符合的TabBar代表和使用一些庫擴展它,例如:利用圖書館的
https://github.com/kumapo/ScrollableTabs
優點:
缺點:
非常感謝。它的工作,但我怎樣才能隱藏在某些視圖控制器中的這個視圖? – Shravya