当我按下按钮值会自动增加,怎么样?

时间:2011-11-18 03:26:56

标签: iphone

  

可能重复:
  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);
}

2 个答案:

答案 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}}停止。当该计时器启动时 - >用任何计数器,缩放或任何其他东西做你想做的事......