正しく動作しないUIScollViewに問題があります。TabBarControllerとNavigationBarControllerで水平ページングが機能しません
だから、これはこのビデオに私の問題です:私はこの同じクラス(コード1)をテストした
let screenSize = UIScreen.main.bounds
let frameHeight: CGFloat = 100
let heightOfNewsCell : CGFloat = 100
var timerForNews = Timer()
var plugeeNews = ["Plugee permet de partager vos fiches de révision !","Ajoutez à vos favoris les fiches de vos amis !"
,"Pourquoi ne pas invitez vos amis a rejoindre Plugee ?","Vous ne savez pas comment utiliser Plugee ? Cliquez ici !"]
let newsOfPlugScrollView : UIScrollView = {
let sv = UIScrollView()
sv.translatesAutoresizingMaskIntoConstraints = false
sv.isPagingEnabled = true
sv.backgroundColor = .gray
return sv
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(r: 227, g: 228, b: 231)
self.navigationItem.title = "News"
setupMyViews()
setupNewsScrollView()
}
func setupMyViews() {
self.view.addSubview(newsOfPlugScrollView)
newsOfPlugScrollView.topAnchor.constraint(equalTo: self.view.topAnchor,constant : 100).isActive = true
newsOfPlugScrollView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
newsOfPlugScrollView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
newsOfPlugScrollView.heightAnchor.constraint(equalToConstant: frameHeight).isActive = true
}
func setupNewsScrollView() {
newsOfPlugScrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: frameHeight)
let view1 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: frameHeight))
view1.translatesAutoresizingMaskIntoConstraints = false
let view2 = UIView(frame: CGRect(x: view.frame.width, y: 0, width: view.frame.width, height: frameHeight))
view1.backgroundColor = .red
view2.backgroundColor = .blue
newsOfPlugScrollView.addSubview(view1)
newsOfPlugScrollView.addSubview(view2)
newsOfPlugScrollView.contentSize = CGSize(width: view.frame.width * 2, height: frameHeight)
}
:https://www.youtube.com/watch?v=IeeCoGm9-b0&feature=youtu.be
そして、これがへのコードの仲間である:
CODE 1空のプロジェクトであり、それは完全に動作します(https://www.youtube.com/edit?o=U&video_id=Z0YvNwtYvAc)。だから私はtabBarControllerのコードから問題cames(しかし、私はなぜか分からない)と思います。
CODE:2:
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
var arrayViews : [UIViewController] = [createAViewController(controller: NewsController(), image: #imageLiteral(resourceName: "IconeTabBar"))]
arrayViews.append(createAViewController(controller: HomeController(), image: #imageLiteral(resourceName: "IconeTabBar")))
arrayViews.append(createAViewController(controller: TopController(), image: #imageLiteral(resourceName: "IconeTabBar")))
viewControllers = arrayViews
self.selectedIndex = 1
}
private func createAViewController(controller : UIViewController, image : UIImage) -> UINavigationController {
let controller = controller
let navController = UINavigationController(rootViewController: controller)
navController.tabBarItem.title = ""
navController.tabBarItem.image = image
navController.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
navController.tabBarItem.title = nil
return navController
}
}
おかげ
これはtabBarControllerコードです。