1
平移手勢限制我需要兩個視圖,該視圖我把圖像view..show..Below如何設置快捷3
我需要設置的限制,圖像中心暫時不會到了超圖的側面..
我試圖代碼但不工作正確的一段時間工作的正確..
func panImage(tap:UIPanGestureRecognizer) {
let minx = (abs(Int((tap.view?.superview?.center.x)!)) - ((Int((tap.view?.superview?.frame.width)!))/2))
let maxx = (abs(Int((tap.view?.superview?.center.x)!)) + ((Int((tap.view?.superview?.frame.width)!))/2))
let miny = (abs(Int((tap.view?.superview?.center.y)!)) - ((Int((tap.view?.superview?.frame.height)!))/2))
let maxy = (abs(Int((tap.view?.superview?.center.y)!)) + ((Int((tap.view?.superview?.frame.height)!))/2))
let translation = tap.translation(in: tap.view)
if(Int(tap.view!.center.x) > maxx)
{tap.view!.center.x = CGFloat(maxx)}
if(Int(tap.view!.center.x) < minx)
{tap.view!.center.x = CGFloat(minx)}
if(Int(tap.view!.center.y) > maxy)
{tap.view!.center.y = CGFloat(maxy)}
if(Int(tap.view!.center.y) < miny)
{tap.view!.center.y = CGFloat(miny)}
if((Int(tap.view!.center.x) >= minx && Int(tap.view!.center.x) <= maxx) && (Int(tap.view!.center.y) <= maxy && Int(tap.view!.center.y) >= miny))
{
tap.view!.center = CGPoint(x: tap.view!.center.x + translation.x, y: tap.view!.center.y + translation.y)
tap.setTranslation(CGPoint(x: 0.0, y: 0.0), in:tap.view)
}
}
你解決ptoblem? –