How to resize UIView by dragging from its edges?

后端 未结 6 1146
-上瘾入骨i
-上瘾入骨i 2020-11-28 21:29

In my iPad app, I want the users to be able to resize a UIView by dragging the view from its edges. I\'ll be using iOS 5 SDK, so what\'s the cleanest approach t

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 21:42

    I'm guessing your UI involves some kind of handles on the sides of the view, and attaching a simple UIPanGestureRecognizer to those handle controls makes the whole problem pretty easy.

    In the action method from the gesture recognizer, just get the -translationInView: relative to the view you're resizing, save off the original frame when the gesture recognizer's state is UIGestureRecognizerStateBegan, and adjust the view's frame continually while the state is UIGestureRecognizerStateChanged.

提交回复
热议问题