gpt4 book ai didi

ios - UIScreenEdgePanGestureRecognizer : top and bottom edges

转载 作者:行者123 更新时间:2023-11-28 18:32:33 27 4
gpt4 key购买 nike

这是否可能使 UIScreenEdgePanGestureRecognizer 处理来自顶部(或底部)边缘的事件?

UIScreenEdgePanGestureRecognizer *gestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(userDidPan:)];
gestureRecognizer.edges = UIRectEdgeTop; // UIRectEdgeBottom
[self.view addGestureRecognizer:gestureRecognizer];

问候。

最佳答案

顶部和底部边缘手势从屏幕边缘触发 20 个像素。

默认情况下,状态栏是可见的并占用前 20 个像素的空间,因此您必须隐藏状态栏才能使用这些(顶部/机器人)UIScreenEdgePanGestureRecognizers,否则委托(delegate)不会被调用。

第一步:

Image

第 2 步:

添加以下代码:

ViewController.h

@interface ViewController : UIViewController<UIGestureRecognizerDelegate>

ViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];

UIScreenEdgePanGestureRecognizer *topEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTopEdgeGesture:)];
topEdgeGesture.edges = UIRectEdgeTop; //UIRectEdgeBottom
topEdgeGesture.delegate = self;
[self.view addGestureRecognizer:topEdgeGesture];




}
- (BOOL) prefersStatusBarHidden
{
return YES;
}

- (void)handleTopEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture
{
NSLog(@"TOP");
}

swift :

class ViewController: UIViewController,UIGestureRecognizerDelegate {

override func viewDidLoad()
{
super.viewDidLoad()


var edgeGesture : UIScreenEdgePanGestureRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action:"handleTopEdgeGesture:")
edgeGesture.edges = UIRectEdge.Top
edgeGesture.delegate = self
self.view.addGestureRecognizer(edgeGesture)

}


func handleTopEdgeGesture(gesture:UIScreenEdgePanGestureRecognizer)
{
println("TOP")
}


override func prefersStatusBarHidden() -> Bool
{
return true
}


override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

关于ios - UIScreenEdgePanGestureRecognizer : top and bottom edges,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25571538/

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