2011-11-18 65 views
0

可能重複:
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

使用此代碼..

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]; 
0

你需要設置NSTimer,這將觸發每x時間UIControlEventTouchDown並在UIControlEventTouchUpInsideUIControlEventTouchCancel上停止。當那個計時器會觸發 - >用任何計數器,變焦或其他東西來做任何你想要的事情...

相關問題