Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you use touchesBegan,touchesMoved and touchesEnded can solve the problem.</p> <p>touchesBegan is to mark the orignPosition.</p> <pre><code>CGPoint orignPosition; CGColor buttonColor; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *touchView = [touch view]; if ([touchView isKindOfClass:[UIButton class]]) { orignPosition = (UIButton *)touchView.center; buttonColor = (UIButton *)touchView.backgroundColor; } } </code></pre> <p>touchesMoved is to let the button move with your finger</p> <pre><code>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *touchView = [touch view]; CGPoint movedPoint = [touch locationInView:yourMainView]; CGPoint deltaVector = CGPointMake(movedPoint.x - lastTouchPoint.x, movedPoint.y - lastTouchPoint.y); lastTouchPoint = movedPoint; if ([touchView isKindOfClass:[UIButton class]]) { touchView.center = CGPointMake(touchView.center.x + deltaVector.x, touchView.center.y + deltaVector.y); } } </code></pre> <p>touchesEnded is to judge whether change your special view`s color</p> <pre><code>- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *touchView = [touch view]; CGPoint movedPoint = [touch locationInView:scrollView]; if ([touchView isKindOfClass:[UIButton class]]) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; (UIButton *)touchView.center = orignPosition; [UIView commitAnimations]; } if(CGRectContainsPoint(specialView.frame, [touch locationInView:yourMainView])) { [yourMainView setBackgroundColor:buttonColor]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload