gpt4 book ai didi

ios - 如何使用uiviewcontroller实现滑出式菜单?

转载 作者:行者123 更新时间:2023-11-29 00:54:00 24 4
gpt4 key购买 nike

Hi all i am working on slide out menu in my app. i present a viewcontroller using the following on mainviewcontroller.

- (IBAction)MenuButton:(id)sender {


tlc = [self.storyboard instantiateViewControllerWithIdentifier:@"SlideOut"];
[tlc.view setFrame:CGRectMake(-800, 0, self.view.frame.size.width, self.view.frame.size.height)];

[self addChildViewController:tlc];
[self.view addSubview:tlc.view];
[tlc didMoveToParentViewController:self];

[UIView animateWithDuration:0.3 animations:^{
[tlc.view setFrame:CGRectMake(-800, 0, self.view.frame.size.width, self.view.frame.size.height)];

swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipGestureLeftAction:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
}];

}

i need to open and hide view using UIGesturerecogniton, so i use the following code, by this code i am able to present view but i am not able to hide it using gesture recognition. please look at my code.

-(void)SwipGestureAction {
NSLog(@"gesture");
UISwipeGestureRecognizer *swiperight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipGestureRightAction:)];
swiperight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swiperight];
}


-(void)SwipGestureRightAction:(UISwipeGestureRecognizer *)swipeRight {

NSLog(@"left");

tlc = [self.storyboard instantiateViewControllerWithIdentifier:@"SlideOut"];
[tlc.view setFrame:CGRectMake(-800, 0, self.view.frame.size.width, self.view.frame.size.height)];

[self addChildViewController:tlc];
[self.view addSubview:tlc.view];
[tlc didMoveToParentViewController:self];


[UIView animateWithDuration:0.3 animations:^{
[tlc.view setFrame:CGRectMake(-800, 0, self.view.frame.size.width, self.view.frame.size.height)];

swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipGestureLeftAction:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];

}];



}


-(void)SwipGestureLeftAction:(UISwipeGestureRecognizer *)swipeRight {

NSLog(@"right");



[UIView animateWithDuration:0.3 animations:^{
[tlc.view setFrame:CGRectMake(-800, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view removeGestureRecognizer:swipeLeft];
}];




}

最佳答案

前几天我也遇到过同样的问题,兄弟;

我已经通过使用以下教程解决了该问题。

这对我来说是完美的答案...我希望这对您也有帮助...:)

https://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path

https://github.com/John-Lluch/SWRevealViewController

关于ios - 如何使用uiviewcontroller实现滑出式菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com