2017-03-17 5 views
1

Ich nehme zwei Ansicht und in dieser Ansicht i nehmen das Bild setzen view..show..BelowWie Pan Gesture-Grenze in schnellen 3

enter image description here

i Grenzwert festlegen müssen, Bildmitte, die nicht gehen .. zu Außenseite der super Aussicht ..

ich diesen Code versuche aber, dass nicht richtig einige Zeit Arbeit Arbeit zu

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) 
    } 
} 
+0

lösen Sie die ptoblem? –

Antwort

0

ich versuche mich, dass Code, der richtige arbeiten ..

hier

func panImage(tap:UIPanGestureRecognizer) { 
    let minx = 0 
    let maxx = minx + Int((tap.view?.superview?.frame.size.width)!) 
    let miny = 0 
    let maxy = miny + Int((tap.view?.superview?.frame.size.height)!) 
    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) 
    } 
} 
+0

Nicht für mich arbeiten. –

+0

was funktioniert nicht ?? –