两个视图控制器的TouchesMoved方法 [英] TouchesMoved method for two view controllers
问题描述
在我的应用中,有两个视图控制器.我在两个视图控制器中都编写了touchesmoved方法.但是,即使我触摸模拟器上的第二个视图控制器,也会调用第一个VC touches移动的方法.
In my app there are two view controllers. I wrote touchesmoved method in both the view controllers. But even if i touch on second view controller on simulator, the first VC touches moved method is called.
//VCOne
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"first view vc move method");
UIStoryboard *storyboard = self.storyboard;
ThreadedView *secViewController = [storyboard instantiateViewControllerWithIdentifier:@"threaded"];
[self.view addSubview:secViewController.view];
[self viewDidUnload];
}
因此,一旦调用了上述方法,它将导航到第二个视图控制器"ViewDIDLoad"方法.在这个文件中,我还写了另一种感动的方法.
So once the above method is called, it will navigate to second view controllers "ViewDIDLoad" method. In this file, i have written one more touches moved method.
//VCTwo
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"second view vc move method");
}
现在,如果我在第二个视图控制器中进行触摸,则将调用第一个VC touches方法,而不是第二个VC touches方法.
Now if i touch in second view controller, the first VC touchesmethod is called instead of second VC touches method.
有没有办法做到这一点?我需要针对不同的视图控制器使用不同的touched移动方法.
Is there any way to do this? I needed different touches moved method for different view controllers.
推荐答案
如果您要从第一个视图控制器过渡到第二个视图控制器,
您可以尝试以下方法:presentModalViewController:animated:
.
If you want to transit from first view controller to second view controller,
you can try this method: presentModalViewController:animated:
.
在第一个视图控制器的touchesMoved:withEvevt:
中
In your touchesMoved:withEvevt:
of first view controller
NSLog(@"first view vc move method");
UIStoryboard *storyboard = self.storyboard;
ThreadedView *secViewController = [storyboard instantiateViewControllerWithIdentifier:@"Threaded"];
[self presentModalViewController:secViewController animated:NO];
在第二个视图控制器中,您可以使用dismissModalViewControllerAnimated:
返回第一个视图控制器.
In second view controller, you can use dismissModalViewControllerAnimated:
to go back to first view controller.
希望这会有所帮助.
这篇关于两个视图控制器的TouchesMoved方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!