2016-11-02 3 views
0

Xcode IBを使用して、16のスタックビューのスクロール可能なグループを作成しようとしています。スクロール。スクロール可能なスタックビューと対話できるようにしたいので、スクロールした直後にそれらが戻ってくるようにしたくありません。iOS:上部に固定要素を持つスタックビューのスタックにバウンスが発生しないスクロール

プログラミングが必要です。私はSwiftでやります。

現在、私が持っている:

  • 静止要素として概要スタックビューの上部に
    • 1水平stackview(これを含むビューの一番上に垂直stackview(Overview Stack View)水平stackview 2つのテキストフィールド)次に、16水平stackviewsは、Y軸上に50個の単位離れた位置に含まれていることのUIViewを含有する以下
    • scrollviewを含有

私は属性インスペクタでBouncesBounces Verticallyでscrollviewを設定している場合、私はstackviewsをスクロールすることができますが、彼らはいつもすぐに立ち直る、と相互作用し、それらが困難または不可能になることがわかります。 BouncesBounces Verticallyを含まない場合、スタックビューのグループはまったくスクロールしません。

のGithubレポhere

この画像は、Xcodeでプロジェクトを示しています

project in Xcode

私は(私はここまで得た方法である)のStackOverflowの質問と回答の数が、どれを読んだことがあります提案されたソリューションの中で私はこれを解決するのに役立っています。

ご協力いただきますようお願い申し上げます。

答えて

0

これは私のような状況のために働く:

  1. はViewControllerをUIScrollViewのデリゲートを作成します。
  2. メインのScrollViewへのコンセントを作成します。
  3. this answerに基づいてコードを追加してください。 (私はいくつかの変更を行いました)

以下のViewControllerのコードを参照してください(githubにもあります)。

これが誰かを助けることを願っています!

import UIKit 

class ViewController: UIViewController, UIScrollViewDelegate { 

    @IBOutlet weak var mainScroll: UIScrollView! 

    let stackHeight: CGFloat = 30.0 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     mainScroll.delegate = self 
     print("----- viewDidLoad -----") 
     let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swiped(_:))) 
     swipeDown.direction = UISwipeGestureRecognizerDirection.Down 
     self.view.addGestureRecognizer(swipeDown) 

     let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swiped(_:))) 
     swipeUp.direction = UISwipeGestureRecognizerDirection.Up 
     self.view.addGestureRecognizer(swipeUp) 
    } 

    func swiped(gesture: UIGestureRecognizer) 
    { 
     if let swipeGesture = gesture as? UISwipeGestureRecognizer 
     { 
      switch swipeGesture.direction 
      { 
      case UISwipeGestureRecognizerDirection.Down: 
       print("DOWN") 
       if (mainScroll.contentOffset.y >= stackHeight) { 
        mainScroll.contentOffset.y = mainScroll.contentOffset.y - stackHeight 
       } 
      case UISwipeGestureRecognizerDirection.Up: 
       print("UP \(mainScroll.contentOffset.y)") 
       if (mainScroll.contentOffset.y <= stackHeight*16) { 
        mainScroll.contentOffset.y = mainScroll.contentOffset.y+stackHeight 
       } 
      default: 
       break 
      } 
     } 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
} 
関連する問題