나는 Swift와 IOS에 익숙하지 않다는 것을 알고 계십시오. 나는 제스처를 사용하여 레이블을 이동합니다. 끝나면 자동으로 새 레이블을 추가하려고합니다. 팬 기능의 끝에서 함수를 호출하려고했지만 새 레이블이 추가되면 이동 한 레이블이 화면에서 벗어납니다. 나는 "panGR.state.rawValue == 3", "panGR.state == UIGestureRecognizerState.ended"및 타이머를 사용하려고 시도했지만 성공하지 못했습니다. 도와주세요.팬 제스처 직후에 함수를 어떻게 호출 할 수 있습니까?
func initGestureRecognizers() {
let panGR = UIPanGestureRecognizer(target: self, action:
#selector(ShapeView.didPan(_:)))
addGestureRecognizer(panGR)
}
func didPan(_ panGR: UIPanGestureRecognizer) {
self.superview!.bringSubview(toFront: self)
var size: CGFloat = 53
var translation = panGR.translation(in: self)
translation = translation.applying(self.transform)
self.center.x += translation.x
self.center.y += translation.y
panGR.setTranslation(CGPoint.zero, in: self)
if panGR.state.rawValue == 1 { // save the last position
let startX = self.center.x
let startY = self.center.y
}
if panGR.state.rawValue == 3 { // when move is finished
// this will remove ability to move tile
removeGestureRecognizer(panGR)
// the following code should replace the moved tile,
// with a new tile, but leave the moved tile where it is.
// BUT - it moves the moved tile to coordinates (x=0,y=0), if
// the following 2 lines are executed.
self.center.x = 0
self.center.y = 0
// if the above 2 lines are not executed, the new tile
// does not get displayed
replaceMovedTile()
}
}
func replaceMovedTile() {
// position new tile
let tapPoint = CGPoint(x: 46 + 22, y: 596 + 22)
let shapeView = ShapeView(origin: tapPoint)
addSubview(shapeView)
}
전에 self.view를 넣어. –
코드를 표시하면 내가 도울 수 있습니다 –
Welcome to Stack Overflow! [ask] 및 [mcve]를 참조하십시오. – Mat