如何通过从边缘拖动来调整UIView的大小? [英] How to resize UIView by dragging from its edges?

查看:271
本文介绍了如何通过从边缘拖动来调整UIView的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPad应用中,我希望用户能够通过从边缘拖动视图来调整 UIView 的大小。我将使用iOS 5 SDK,那么最简洁的方法是什么?如果没有处理touchesBegan,touchesMoved,等等,有没有其他方法可以做到这一点?

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 to do this? Are there any alternatives to achieving this without dealing with touchesBegan, touchesMoved,... etc?

推荐答案

我在猜你的用户界面涉及视图两侧的某种句柄,并将简单的 UIPanGestureRecognizer 附加到这些句柄控件,使整个问题变得非常简单。

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.

在手势识别器的动作方法中,只需获取相对于视图的 -translationInView:调整大小,当手势识别器的状态为 UIGestureRecognizerStateBegan 时保存原始帧,并在状态为 UIGestureRecognizerStateChanged

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.

这篇关于如何通过从边缘拖动来调整UIView的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆