本文介绍了如何通过从边缘拖动来调整 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?

推荐答案

我猜你的 UI 涉及视图两侧的某种句柄,并附加一个简单的 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 的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:30
查看更多