TouchesBegan 在下一个视图控制器中被识别
TouchesBegan recognised in next view controller
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
NSLog(@"touch recognised");
CGPoint location = [aTouch locationInView:_mainView];
__block NSString *option = [[NSString alloc] init];
__block NSString *type = [[NSString alloc] init];
for (Selectors *tempView in _mainView.subviews) {
if (CGRectContainsPoint(tempView.frame, location)) {
NSLog(@"%@ : %@", tempView.option, tempView.type);
option = tempView.option;
type = tempView.type;
break;
}
}
[self moveToNextWeldCustomViewWithOption:option andType:type];
}
在我之前的 UIVIewController 中 - 然后我们在这里展示下一个 UIViewController
-(void)moveToNextWeldCustomViewWithOption:(NSString *)option andType:(NSString *)type {
WeldDesignViewController *lobby = [self.storyboard instantiateViewControllerWithIdentifier:@"WeldDesignViewController"];
lobby.option = option;
lobby.type = type;
[self presentViewController:lobby animated:NO completion:nil];
}
在下一个 UIViewController 中,直到 viewDidAppear 方法我才做任何事情 - 但是,在下一个 viewcontroller 中仍然可以识别开始的触摸。
我认为问题在于您调用的 VC "lobby" 在您提交后正在被释放。这使得它在响应者链中不被考虑。将该引用移动到呈现视图控制器的 属性:
@property (nonatomic, strong) WeldDesignViewController* lobby;
// ...
-(void)moveToNextWeldCustomViewWithOption:(NSString *)option andType:(NSString *)type {
self.lobby = [self.storyboard instantiateViewControllerWithIdentifier:@"WeldDesignViewController"];
lobby.option = option;
lobby.type = type;
[self presentViewController:self.lobby animated:NO completion:nil];
}
您可能还需要在所呈现的 VC 中实现 touchesBagan
,因为它可能沿着响应链到达前一个控制器。
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
NSLog(@"touch recognised");
CGPoint location = [aTouch locationInView:_mainView];
__block NSString *option = [[NSString alloc] init];
__block NSString *type = [[NSString alloc] init];
for (Selectors *tempView in _mainView.subviews) {
if (CGRectContainsPoint(tempView.frame, location)) {
NSLog(@"%@ : %@", tempView.option, tempView.type);
option = tempView.option;
type = tempView.type;
break;
}
}
[self moveToNextWeldCustomViewWithOption:option andType:type];
}
在我之前的 UIVIewController 中 - 然后我们在这里展示下一个 UIViewController
-(void)moveToNextWeldCustomViewWithOption:(NSString *)option andType:(NSString *)type {
WeldDesignViewController *lobby = [self.storyboard instantiateViewControllerWithIdentifier:@"WeldDesignViewController"];
lobby.option = option;
lobby.type = type;
[self presentViewController:lobby animated:NO completion:nil];
}
在下一个 UIViewController 中,直到 viewDidAppear 方法我才做任何事情 - 但是,在下一个 viewcontroller 中仍然可以识别开始的触摸。
我认为问题在于您调用的 VC "lobby" 在您提交后正在被释放。这使得它在响应者链中不被考虑。将该引用移动到呈现视图控制器的 属性:
@property (nonatomic, strong) WeldDesignViewController* lobby;
// ...
-(void)moveToNextWeldCustomViewWithOption:(NSString *)option andType:(NSString *)type {
self.lobby = [self.storyboard instantiateViewControllerWithIdentifier:@"WeldDesignViewController"];
lobby.option = option;
lobby.type = type;
[self presentViewController:self.lobby animated:NO completion:nil];
}
您可能还需要在所呈现的 VC 中实现 touchesBagan
,因为它可能沿着响应链到达前一个控制器。