UIView drag (image and text)

前端 未结 6 1879
悲&欢浪女
悲&欢浪女 2020-11-27 13:59

Is it possible to drag UIView around the iOS screen while it has both image and text? e.g. small cards. Could you point me to the similar (solved) topic? I haven\'t found an

6条回答
  •  有刺的猬
    2020-11-27 14:41

    This is what a neat solution, based on pepouze's answer, would look like (tested, it works!)

    - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        UITouch *aTouch = [touches anyObject];
        CGPoint location = [aTouch locationInView:self];
        CGPoint previousLocation = [aTouch previousLocationInView:self];
        self.frame = CGRectOffset(self.frame, (location.x - previousLocation.x), (location.y - previousLocation.y));
    }
    

提交回复
热议问题