0

私は現在、Snapchat ScrollViewと同様のUIを持つアプリケーションを持っています。 MainViewControllerは3つの子ViewControllersが子ViewControllersとして追加されているUIScrollが、含まれています子のViewControllerからのオフセットUIScrollView

override func viewDidLoad() { 

    super.viewDidLoad() 
    scrollView.contentSize = CGSizeMake((self.view.bounds.width*3 + 4), self.view.bounds.height) 
    self.view.addSubview(scrollView) 

    let view1 = UIView(frame: CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height)) 
    scrollView.addSubview(view1) 
    let aVC = self.storyboard?.instantiateViewControllerWithIdentifier("One") 
    view1.addSubview(aVC!.view) 
    self.addChildViewController(aVC!) 

    let view2 = UIView(frame: CGRectMake((self.view.bounds.width), 0, self.view.bounds.width, self.view.bounds.height)) 
    scrollView.addSubview(view2) 
    let bVC = self.storyboard?.instantiateViewControllerWithIdentifier("Two") 
    view2.addSubview(bVC!.view) 
    self.addChildViewController(bVC!) 

    let view3 = UIView(frame: CGRectMake(2*view.bounds.width), 0, self.view.bounds.width, self.view.bounds.height)) 
    scrollView.addSubview(view3) 
    let cVC = self.storyboard?.instantiateViewControllerWithIdentifier("LocationViewController") 
    view3.addSubview(cVC!.view) 
    self.addChildViewController(cVC!) 

    scrollView.contentOffset = CGPointMake(self.view.frame.width, 0 
    } 

私はボタン2 ScrollViewには、いずれかの左または右のビューコントローラを相殺する途中のViewControllerを追加しようとします。 MainContControllerでsetContentOffset()を使うことができますが、これは子ビューのコントローラでは呼び出せません。 self.presentingViewControllerとself.parentViewControllerはともにnilを返します。

子ViewController内のUIScrollViewに対してsetContentOffset()を呼び出す最も良い方法は何ですか?

答えて

0

これは、delegationの場合によく似ています。変更されるビューを持つViewControllerにデリゲートを追加し、親ViewControllerをデリゲートとして取得させます。次に、ビューを検査し、それに応じてサイズを変更することができます。

関連する問題