gpt4 book ai didi

objective-c - 通过 UIView 的滑动滑出导航以覆盖另一个 UIView

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:14:05 25 4
gpt4 key购买 nike

在我对这种导航技术的研究中,我发现了 this post by Nick Harris我想这是一个好的开始。但是,我想要的与此略有不同。您可以将其视为 iOS 的通知中心,您只需从顶部滑动即可显示 View ,然后向后滑动即可再次隐藏它。在我的例子中,我希望通过向左滑动手势从屏幕右侧显示一个隐藏的 UIView 并通过相同的手势(这次向右)再次隐藏它。

我已经设法解决了我以前的 post关于显示/隐藏 UIView。我想添加的一件事是滑动手势。

我不想像 Nick Harris 那样调整我的应用委托(delegate)来执行此操作。因此,如果有人对我如何做到这一点有任何想法/代码示例,我将不胜感激。

阐明一些光:)

最佳答案

您可以通过向左滑动手势从屏幕右侧显示一个隐藏的 UIView,也可以通过相同的手势(这次向右滑动)再次隐藏它。添加过渡。

在 .h 文件中添加 BOOL didNotSwipe 在 .m 文件中添加其值 didNotSwipe = TRUE viewDidLoad 方法

将带有不同选择器的左右方向滑动手势添加到您的 self.view。

 UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];

UISwipeGestureRecognizer *recognizer1;
recognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeleft:)];
[recognizer1 setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizer1];
[recognizer1 release];

当向左滑动时调用此方法:

 -(void)swipeleft:(UISwipeGestureRecognizer *)swipeGesture 
{
if (didNotSwipe) {
didNotSwipe = FALSE;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:kCATransition];
[self.view addSubView:self.overlayView];
//[self.overlayView setFrame:CGRectMake(0,0,self.overlayView.frame.size.width,self.overlayView.frame.size.height)];
}
}

当向右滑动时这个方法:

 -(void)swipeRight:(UISwipeGestureRecognizer *)swipeGesture
{
if(!didNotSwipe){
didNotSwipe = TRUE;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setDuration:0.40];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:kCATransition];
[self.overlayView removeFromSuperView];
}
}

关于objective-c - 通过 UIView 的滑动滑出导航以覆盖另一个 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12066200/

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