UIView drag (image and text)

前端 未结 6 1909
悲&欢浪女
悲&欢浪女 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:35

    Here is a solution to drag a custom UIView (it can be scaled or rotated through its transform), which can hold images and/or text (just edit the Tile.xib as required):

    app screenshot

    - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
    {
        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInView:self];
        CGPoint previous = [touch previousLocationInView:self];
    
        if (!CGAffineTransformIsIdentity(self.transform)) {
            location = CGPointApplyAffineTransform(location, self.transform);
            previous = CGPointApplyAffineTransform(previous, self.transform);
        }
    
        self.frame = CGRectOffset(self.frame,
                                  (location.x - previous.x),
                                  (location.y - previous.y));
    }
    

提交回复
热议问题