作者:Mitchell
- 自定義view
- 重寫touch方法
- 只要不斷的摸當(dāng)前的view就會調(diào)用
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// 拿到UITouch就能獲取當(dāng)前點
UITouch *touch = [touches anyObject];
// 獲取當(dāng)前點
CGPoint curP = [touch locationInView:self];
// 獲取上一個點
CGPoint preP = [touch previousLocationInView:self];
// 獲取手指x軸偏移量
CGFloat offsetX = curP.x - preP.x;
// 獲取手指y軸偏移量
CGFloat offsetY = curP.y - preP.y;
// 移動當(dāng)前view
self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY);
}
// 觸摸事件被迫打斷(電話打來)
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者