可能重复:
Way to make a UIButton continuously fire during a press-and-hold situation?
我在相机视图中有两个自定义按钮,一个是放大,另一个是缩小按钮按下的值将增加1,2...
,但我想按下放大或缩小按钮时值会自动增加并释放按钮值会停止,怎么样?请任何人帮助我
我尝试了代码
zoomin=[UIButton buttonWithType:UIButtonTypeCustom];
zoomin.frame=CGRectMake(60, 410, 60, 60);
[zoomin setBackgroundImage:[UIImage imageNamed:@"zoomplus.png"] forState:UIControlStateNormal];
[zoomin addTarget:self action:@selector(CameraZoomIn) forControlEvents:UIControlEventTouchUpInside];
[buttonView addSubview:zoomin];
-(void)CameraZoomIn
{
x=x+0.090253;
y=y+0.090253;
NSLog(@"X : %f, Y : %f",x,y);
imgpicker.cameraViewTransform = CGAffineTransformMakeScale(x,y);
}
答案 0 :(得分:0)
使用此代码..
zoomin = [UIButton buttonWithType:UIButtonTypeCustom];
zoomin = CGRectMake(60, 410, 60, 60);
UIImage * zoominImage = [UIImage imageNamed:@"zoomplus.png"];
[zoomin setImage:jumpbtnImage forState:UIControlStateNormal];
zoomin.backgroundColor = [UIColor clearColor];
[zoomin addTarget:self action:@selector(CameraZoomIn) forControlEvents:UIControlEventTouchDown];
[zoomin addTarget:self action:@selector(stopZoom) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: zoomin];
答案 1 :(得分:0)
您需要设置NSTimer
,该x
会在UIControlEventTouchDown
上每隔UIControlEventTouchUpInside
次触发,并在UIControlEventTouchCancel
或{{1}}停止。当该计时器启动时 - >用任何计数器,缩放或任何其他东西做你想做的事......