2016-02-08 75 views

回答

1

添加操作爲您UIPanGestureRecognizer和使用translation

func wasDragged(gesture: UIPanGestureRecognizer) { 
    let translation = gesture.translationInView(self.view) 
    // Do your resizing here, e.g. from a 
    customView.frame.size.width = currentFrame.width + translation.x 
    customView.frame.size.height = currentFrame.height + translation.y 

    if gesture.state == .Ended { 
     currentFrame = customView.frame 
    } 
} 

使用這種方法,添加一個CGRect變量存儲currentFrame

+0

我不明白。什麼是currentFrame? –

+0

而且,customView.frame.width是隻能得到的屬性 –

+0

@OkadzakiTomoe固定,它應該是'frame.size.width'。 'customView'是你調整大小的視圖,'currentFrame'只是一個屬性,你應該在手勢結束後保存'customView'的框架,這樣調整大小才能正常工作。 – xoudini