Drag separator to resize UIViews

后端 未结 4 1705
旧时难觅i
旧时难觅i 2021-02-10 14:15

What would be to the best way of implementing an interface which consists of UIViews which are separated by a line, and the line can resize the views?

In it\'s simplest

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 15:02

    You do essentially need to make the line-view draggable, but it doesn't need to be complicated.

    1. Put viewA and viewB into a containerView
    2. Add a pan gesture recognizer to the containerView configured for a single touch and set its delegate to your controller.
    3. Implement gestureRecognizerShouldBegin: from the UIGestureRecognizerDelegate protocol and only allow it to begin if the touch in in the vicinity of the line-view.
    4. In the gesture handler get the touch position in the containerView and set the line-view position and frames for viewA and viewB

    That's pretty much it.

提交回复
热议问题