0

如何在按住 uibutton 的同时移动 uiimageview?旧代码就像您必须按 2 或 3 次才能再次移动,而长按不起作用,因为它在内部进行了修饰。

-(IBAction) MoveRightButton : (id) sender {

[self animateRight];
[self rightTimer];

}

-(IBAction) stopRight {

[image stopAnimating];
[rightTimer invalidate];
}

-(void) animateRight {
with animateRight images and start animating.
}

-(void) goRight {
[UIView animateWithDuration : 0.5 animation : ^{
image.frame = CGRectMake (image.frame.origin.x + 10, image.frame.origin.y,image.frame.size.width, image.frame.size.height);
}];
[self stopRight];
}

-(void) rightTimer {
rightTimer = [some NSTimer with selector of (goright)];
4

2 回答 2

0

Create two IBAction methods for your UIButton using sent events;

Touch Down - The associated method will be called when the button is first pressed.

Touch Up Inside - The associated method will be called when the button is released.

So in the "Touch Down" method, begin the animation as you have it, and in the "Touch Up Inside" method - stop it using something like:

#import <QuartzCore/QuartzCore.h>

[myView.layer removeAllAnimations];

EDIT:

(1) View your .xib, and create a UIButton.

(2) Hold "alt" down and click your .h file. This'll bring up that file in the assistant editor - but will enable you to still work on the xib.

(3) Hold down "ctrl", and then click-drag from the UIButton to the .h file (below @interface).

(4) In the resulting pop-up, select "Action" in the connection field and name your method. The event field contains many options, of which you're interested in Touch Down and Touch Up Inside. Choose one, and click connect.

(5) Repeat for the event you didn't do in (4) (but obviously change the name). Those methods will have automatically been created in your .m file so go there and edit them as you please!

于 2013-01-07T21:27:42.400 回答
0

尝试映射此操作

UIControlEventTouchDownRepeat instead of UIControlEventTouchUpInside       

方法

-(IBAction)MoveRightButton:(id)发件人

于 2013-01-07T16:50:29.790 回答