我有一个需要调整大小的垂直线(UIView)。目前我是使用捏合手势来实现的,但现在我需要使用滑动手势,并从我滑动的那一侧增加或减少高度。例如,如果我从线的顶端向下滑动,则线必须仅从顶部缩小。底部必须保持锚定在原始位置。
我该如何做到这一点?
我还需要能够移动图像,我已经使用UIPanGestureRecognizer实现了这一点。
这是我正在尝试的:
我在垂直线的顶端和底端各放置了一个小的UIView作为标记。我将它们用作标记。现在,我能够上下移动顶部标记。我需要将线的大小调整为两个标记之间的距离,并保持线的底端与底部标记的位置相同。
我该如何做到这一点?
我还需要能够移动图像,我已经使用UIPanGestureRecognizer实现了这一点。
这是我正在尝试的:
我在垂直线的顶端和底端各放置了一个小的UIView作为标记。我将它们用作标记。现在,我能够上下移动顶部标记。我需要将线的大小调整为两个标记之间的距离,并保持线的底端与底部标记的位置相同。
func draggedViewForTopMarker(sender: UIPanGestureRecognizer) {
//To move the top marker
var translation = sender.translationInView(self.view)
sender.view!.center = CGPointMake(sender.view!.center.x, sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
//Find distance between the markers
var distanceBetweenMarkers = (sender.view!.center.y + translation.y) - self.bottomMarker.center.y
print(distanceBetweenMarkers)
if (distanceBetweenMarkers < 0) {
distanceBetweenMarkers = distanceBetweenMarkers*(-1)
}
//**TRYING** to resize the line to have the same height as the distance between the two markers AND make sure its positioned between the markers and the bottom end of the line is still in the same place as it was originally.
var newFrame = CGRectMake(sender.view!.center.x, distanceBetweenMarkers/2, vertical.frame.width, distanceBetweenMarkers)
vertical.frame = newFrame
}
我也愿意尝试不同的方法,或者解决我在这种方法中遇到的问题的方案!
您可以在App Store上查看Photo Measures Lite,以更好地理解我所说的“仅从一侧调整线条”的含义。
非常感谢!