0
我在StoryBoard中的UIViewController上設置了以下平移手勢代碼。如何從泛姿態觸發棘手?
在viewDidLoad中:
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
[self.view addGestureRecognizer:panRecognizer];
然後我有以下稱爲:
#pragma mark - GESTURE RECOGNIZERS
- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{
CGPoint velocity = [panRecognizer velocityInView:self.view];
NSLog(@"Pan Detected.");
if(velocity.x > 0)
{
NSLog(@"Pan went right.");
}
else
{
NSLog(@"Pan went left.");
if (panRecognizer.state == UIGestureRecognizerStateChanged)
NSLog(@"State Changed.");
}
}
上面的代碼火災時,我拖我的手指由左到右。我希望它只在從屏幕右邊緣拖動時觸發。然後我想繼續使用另一個StoryBoard上的UIViewController。 (我想在設置屏幕上從右邊拖動到應用程序的主屏幕上)。 UIViewController只需部分拖到屏幕上即可。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"prepareForSegue: %@", segue.identifier);
if([segue.identifier isEqualToString:@"Settings"])
{
NSLog(@"Show Settings View Controller");
OLStoryboardLink *storyboardLink = segue.destinationViewController;
//send the string
storyboardLink.setStoryboardName = @"Settings";
storyboardLink.transitioningDelegate = self;
[self presentViewController:storyboardLink animated:YES completion:nil];
}
}
如何從屏幕的右邊緣觸發平移手勢?
我目前做這與RSStoryboardLink,但我不知道如何從一個手勢觸發它。我可以使它與UIButton水龍頭一起工作。 – motionpotion 2014-10-04 16:00:53
看到我編輯的答案。 – Imotep 2014-10-04 16:11:21
你有更完整的代碼示例嗎?我如何執行SegueWithIdentifier:從我的panDetected代碼? – motionpotion 2014-10-04 16:13:26