ios - 拖放而不删除 UIBUTTON
<p><p>问题是我必须触摸两次才能拖动按钮..当我第一次触摸时,它会自动复制按钮并触摸结束..现在我想要的是第一次触摸并拖动.. </p>
<pre><code>point = [[ anyObject] locationInView:self.view];
NSData *archivedData = ;
UIButton * anotherButton =(id) ;
UIImage *senderImage=[(id)touch imageForState:UIControlStateNormal];
CGImageRef cgImage = ;
UIImage *copyOfImage = [ initWithCGImage:cgImage];
;
;
;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><h2>这应该可以解决您的问题,</h2>
<p>1) 声明,</p>
<pre><code>@property(weak, nonatomic) IBOutlet UIButton *button;
@property(strong, nonatomic) UIButton *tempButton;
</code></pre>
<p><br/>
2)将手势识别器添加到您的按钮,</p>
<pre><code>UIPanGestureRecognizer *panGesture = [ initWithTarget:self action:@selector(handlePan:)];
;
</code></pre>
<p><br/>
3) 添加这个句柄方法,</p>
<pre><code>- (void) handlePan:(UIPanGestureRecognizer *)recognizer {
switch(){
caseUIGestureRecognizerStatePossible : {
}break;
caseUIGestureRecognizerStateBegan: {
UIButton *button = ;
;
;
;
self.tempButton = button;
NSLog(@"UIGestureRecognizerStateBegan");
}break;
caseUIGestureRecognizerStateChanged: {
CGPoint translation = ;
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
;
}break;
caseUIGestureRecognizerStateCancelled: {
}break;
caseUIGestureRecognizerStateFailed: {
}break;
case UIGestureRecognizerStateRecognized: {
;
self.tempButton = nil;
}break;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 拖放而不删除 UIBUTTON,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/16523675/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/16523675/
</a>
</p>
页:
[1]