我四处寻找解决办法,但他们都没有回答我的问题。因此,我从我的项目后退一步,尝试解决这个特性。我使用AppDelegate来帮助我更清楚地看到代码。
当用户触摸并按住屏幕时,我希望菜单滑出。当用户释放他们的触觉时,它应该会向后滑动。
但是,我无法发送手势参数。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];
ScrollViewController *topViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"Scroll"];
MenuViewController *underLeftViewController = (MenuViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"Menu"];
ECSlidingViewController *slidingViewController = [[ECSlidingViewController alloc] initWithTopViewController:topViewController];
slidingViewController.underLeftViewController = underLeftViewController;
[slidingViewController.view addGestureRecognizer:slidingViewController.panGesture];
self.window.rootViewController = slidingViewController;
// HOW DO I PASS GESTURE DATA?
UILongPressGestureRecognizer *revealMenuRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:slidingViewController.underLeftViewController action:@selector(revealMenu: GESTURE PARAMETERS? )];
[topViewController.view addGestureRecognizer:revealMenuRecognizer];
return YES;
}MenuViewController.m
- (void)revealMenu:(UILongPressGestureRecognizer *)longPressRecognizer {
if (longPressRecognizer.state == UIGestureRecognizerStateBegan) {
[self.slidingViewController anchorTopViewToRightAnimated:YES];
} else {
if (longPressRecognizer.state == UIGestureRecognizerStateCancelled
|| longPressRecognizer.state == UIGestureRecognizerStateFailed
|| longPressRecognizer.state == UIGestureRecognizerStateEnded)
{
[self.slidingViewController resetTopViewAnimated:YES];
}
}
}发布于 2015-11-01 23:19:04
应该是action:@selector(revealMenu:)];,放置冒号就足以让手势识别器将UIGestureRecognizer对象传递给操作。阅读UIGestureRecognizer参考指南
所调用的操作方法必须符合下列签名之一:
符合后一种签名的方法允许目标在某些情况下查询发送消息的手势识别器以获得附加信息。例如,自上次调用该手势的动作方法以来,目标可以请求UIRotationGestureRecognizer对象的旋转角度(以弧度表示)。
如果您不关心对象,请关闭冒号,如果您需要它的数据,请包含它。你想要后者。
https://stackoverflow.com/questions/33466294
复制相似问题