gpt4 book ai didi

iphone - MKMapView 在点击时隐藏导航栏,就像在照片应用程序中一样,而不会丢失 MKMapView 的功能

转载 作者:行者123 更新时间:2023-12-05 09:24:58 24 4
gpt4 key购买 nike

我想像照片应用程序中那样隐藏和显示导航栏但不会丢失 MKMapView 的功能。用户仍然应该能够双击进行缩放、捏合和缩放,并能够选择注释。

我试过:

 UITapGestureRecognizer* tapRec = [[UITapGestureRecognizer alloc] 
initWithTarget:self action:@selector(hideBar:)];
[self.myMKMapView addGestureRecognizer:tapRec];
[tapRec release];

但随后用户无法再选择注释!而且它还会在双击时隐藏。

有什么想法吗?

最佳答案

我知道,这几乎晚了整整一年,但我希望有人可以利用它。根据@Cocoanetics 的回答,这是我的做法:

BOOL                mapReceivedDoubleTap;

...

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMap:)];
[tapGestureRecognizer setDelegate:self];
[_mapView addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];

...

// ignore annotations
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return (![[touch view] isKindOfClass:[MKAnnotationView class]]);
}

// take care of double taps for zoom
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

if([otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *tr = (UITapGestureRecognizer *)otherGestureRecognizer;
if(tr.numberOfTapsRequired == 2)
mapReceivedDoubleTap = YES;
}

return NO;
}

- (void)didTapMap:(UITapGestureRecognizer *)tapGestureRecognizer {

mapReceivedDoubleTap = NO;

// hide/show on delay
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, .2f * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if(!mapReceivedDoubleTap)
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden animated:YES];
});
}

swift

import MapKit

class MapViewController: UIViewController, UIGestureRecognizerDelegate {

@IBOutlet weak var myMapView: MKMapView!

var mapReceivedDoubleTap = false

override func viewDidLoad() {
super.viewDidLoad()

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(MapViewController.didTapMap(_:)))
tapGestureRecognizer.delegate = self
myMapView.addGestureRecognizer(tapGestureRecognizer)
}

// ignore annotations
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
return !touch.isKindOfClass(MKAnnotationView)
}

// take care of double taps for zoom
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {

if otherGestureRecognizer.isKindOfClass(UITapGestureRecognizer) {
let tr = otherGestureRecognizer as! UITapGestureRecognizer
if tr.numberOfTapsRequired == 2 {
mapReceivedDoubleTap = true
}
}

return false
}

func didTapMap(gestureRecognizer: UIGestureRecognizer) {

mapReceivedDoubleTap = false

// hide/show on delay
let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.2 * Double(NSEC_PER_SEC)))
dispatch_after(popTime, dispatch_get_main_queue(), {
if !self.mapReceivedDoubleTap {
self.navigationController?.setNavigationBarHidden(!(self.navigationController?.navigationBarHidden)!, animated: true)
}
})
}
}

关于iphone - MKMapView 在点击时隐藏导航栏,就像在照片应用程序中一样,而不会丢失 MKMapView 的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7346451/

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