UIImagesを使用してギャラリーを表示するアプリケーションを開発していますUIScrollView。私の質問は、タップしzoomてダブルタップしてzoomアウトする方法UIScrollViewです。
			
			21668 次
		
2 に答える
            39        
        
		
viewController に UITapGestureRecognizer - docs here -を実装する必要があります
- (void)viewDidLoad
{
    [super viewDidLoad];       
    // what object is going to handle the gesture when it gets recognised ?
    // the argument for tap is the gesture that caused this message to be sent
    UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce:)];
    UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)];
    // set number of taps required
    tapOnce.numberOfTapsRequired = 1;
    tapTwice.numberOfTapsRequired = 2;
    // stops tapOnce from overriding tapTwice
    [tapOnce requireGestureRecognizerToFail:tapTwice];
    // now add the gesture recogniser to a view 
    // this will be the view that recognises the gesture  
    [self.view addGestureRecognizer:tapOnce];
    [self.view addGestureRecognizer:tapTwice];
}
基本的に、このコードは、メソッドに aUITapGestureが登録されている場合、シングルタップかダブルタップかに応じて、tapOnceまたはtapTwiceが呼び出されることを示しています。したがって、これらのタップ メソッドを に追加する必要があります。self.viewselfUIViewController
- (void)tapOnce:(UIGestureRecognizer *)gesture
{
    //on a single  tap, call zoomToRect in UIScrollView
    [self.myScrollView zoomToRect:rectToZoomInTo animated:NO];
}
- (void)tapTwice:(UIGestureRecognizer *)gesture
{
    //on a double tap, call zoomToRect in UIScrollView
    [self.myScrollView zoomToRect:rectToZoomOutTo animated:NO];
}
それが役立つことを願っています
于 2012-01-25T20:10:08.330   に答える