问题是 - 有没有办法限制MKMapView的最大缩放级别?或者有没有办法跟踪用户何时缩放到没有可用地图图像的级别?
如何在实例上检测到单击MKMapView
?我是否必须继承MKMapView
并重写该touchesEnded
方法?
谢谢,
-克里斯
我想在UITableView上实现一个捏合/外出,我已经看了几个方法,包括这个:
但是虽然我可以创建一个UIViewTouch
对象并将其覆盖到我的UITableView上,滚动事件不会被转发到我的UITableView,我仍然可以选择单元格,并且它们通过触发转换到新的ViewController对象来正确响应.但是,尽管传递了touchesBegan,touchesMoved和touchesEnded事件,但我无法滚动UITableView.
似乎只有触摸在该视图的边界内开始时才会调用UIView的所有触摸方法.有没有办法让视图响应在视图外触摸但随后将手指拖入视图的用户?
如果重要,我的具体应用是拖动MKPinAnnotationView(使用内置的4.0拖动).如果用户将一个引脚拖动到另一个视图(这恰好是一个AnnotationView,但它可能是任何东西),我想要发生一些事情.在我放开引脚之前,没有调用拖动的方法; 并且没有方法没有被拖动的UIView似乎被调用,除非我从视图中触摸开始.
因为superview是MKMapView,所以很难只使用touchesMoved事件并检查用户是否在正确的位置.谢谢!
在我的iphone应用程序中,我使用MapKit和MKMapView以及自定义MKAnnotationView.
问题是当注释在地图上重叠时(在我的应用中,注释是照片而这些照片可能重叠),当你点击前面出现的注释时,它是另一个注释(在背面)接收事件(似乎是随机的) ).
我没有找到任何方法将事件发送到前端注释.我不敢相信这个bug /问题没有任何解决方案!
stackoverflow上的Z排序和重叠注释问题的顺序对我没有多大帮助.
欢迎任何想法(即使是肮脏的解决方案)!
这是我的一些代码(没什么特别的,很常见):
CustomAnnotation.h
@interface CustomAnnotation : NSObject <MKAnnotation> {
@private
CustomAnnotationView* view;
}
@property (nonatomic, retain) CustomAnnotationView* view;
@end
Run Code Online (Sandbox Code Playgroud)
CustomAnnotation.m
@implementation CustomAnnotation
@synthetize view;
Run Code Online (Sandbox Code Playgroud)
CustomAnnotationView.h
@interface CustomAnnotationView : MKAnnotationView {
}
@end
Run Code Online (Sandbox Code Playgroud)
CustomAnnotationView.m
@implementation CustomAnnotationView
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// Do something related to the annotation tapped
}
@end
Run Code Online (Sandbox Code Playgroud)
主类... //添加了注释,其中一些与其他注释重叠.
- (void)addAnnotation:(CustomAnnotation*)annotation {
[map addAnnotation:annotation];
}
...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
NSString* identifier …
Run Code Online (Sandbox Code Playgroud) 在我正在设计的应用程序中,我有一个MKMapView
覆盖它(自定义MKPolylines
btw),我希望能够检测这些覆盖上的触摸事件,并为每个覆盖分配特定的操作.有人可以帮我这个吗?谢谢 !
贝尼亚
我一直在尝试在我的应用程序中实现Facebook"喜欢"操作.使用requestWithGraphPath:andParams:andHttpMethod:andDelegate:方法我能够喜欢帖子,照片以及除Facebook页面之外的所有内容.网络上的论坛表示,这是出于某些安全原因,以防止某些垃圾邮件应用强行让用户"喜欢"他们的网页.这完全有道理.因此,这提出了一个问题,即在没有他们知识的情况下让用户"喜欢"帖子或照片并不违法?而且,是的,这完全超出了这个问题的范围;-)
说到这一点,我用谷歌搜索了什么是最有利的解决方案,大多数论坛/帖子都建议在UIWebView中添加"Like"按钮iFrame是现在更好/唯一的方式.所以我只想与你们仔细检查一下,从iOS应用程序中更好地了解Facebook页面,而不必使用最近的UIWebView,或者我只需要使用它?
我真的很感激大家!
3.0 SDK中是否存在禁用实时缩放和拦截MKMapView放大手势的错误?我有一些真正简单的代码,所以我可以检测到tap事件,但有两个问题:
在hitTest中,如果我返回"map"视图,MKMapView功能效果很好,但我没有机会拦截事件.
有任何想法吗?
MyMapView.h:
@interface MyMapView : MKMapView
{
UIView *map;
}
Run Code Online (Sandbox Code Playgroud)
MyMapView.m:
- (id)initWithFrame:(CGRect)frame
{
if (![super initWithFrame:frame])
return nil;
self.multipleTouchEnabled = true;
return self;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
NSLog(@"Hit Test");
map = [super hitTest:point withEvent:event];
return self;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s", __FUNCTION__);
[map touchesCancelled:touches withEvent:event];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event
{
NSLog(@"%s", __FUNCTION__);
[map touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
NSLog(@"%s, %x", __FUNCTION__, mViewTouched);
[map touchesMoved:touches withEvent:event]; …
Run Code Online (Sandbox Code Playgroud) 我有一个MKMapView
ViewController,并希望在他/她用这些方法触摸地图时检测用户的手势:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
Run Code Online (Sandbox Code Playgroud)
该应用程序适用于iOS 3,iOS 4,但当我在iOS 5上运行iPhone调试应用程序时,我看到此消息:
Pre-iOS 5.0 touch delivery method forwarding relied upon. Forwarding -touchesCancelled:withEvent: to <MKAnnotationContainerView: 0x634790; frame = (0 0; 262144 262144); autoresizesSubviews = NO; layer = <CALayer: 0x634710>>
Run Code Online (Sandbox Code Playgroud)
并且未达到上述4种方法中的代码.
你知道怎么解决吗?
谢谢.
在我的应用程序中,我有一个带有几个 MKGeodesicPolylines 的 MapView。我希望能够识别这些线上的触摸手势。使用以下方法添加叠加层:
[_mapView addOverlay:polyline];
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
if ([overlay class] == [MKGeodesicPolyline class])
{
MKPolylineRenderer *renderer = [[[MKPolylineRenderer alloc] initWithPolyline:overlay] autorelease];
renderer.lineWidth = 4.0;
renderer.strokeColor = [UIColor blackColor];
return renderer;
}
return nil;
}
Run Code Online (Sandbox Code Playgroud)
我试过WildcardGestureRecognizer应该符合我的目的。这是我正在使用的代码:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
.... MapView init ....
WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
tapInterceptor.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [touches anyObject]; …
Run Code Online (Sandbox Code Playgroud) 我UIMapView
按照这个问题的接受答案中描述的方式实现了手势识别器:如何拦截触摸MKMapView或UIWebView对象上的事件?
可以正确识别单个触摸.然而,当我改变了我的类的超从UIGestureRecognizer
到UIPinchGestureRecognizer
以识别地图缩放,一切都停止了工作.现在只有当用户双击地图上的注释时才会发生TouchesEnded事件(不知道,为什么!)并且当用户捏住地图时不会发生(放大或缩小无关紧要).
PS我正在使用iOS SDK 4.3并在模拟器中测试我的应用程序,如果这很重要.
mapViewController.m的代码 - viewDidLoad方法:
- (void)viewDidLoad
{
[super viewDidLoad];
MapGestureRecognizer *changeMapPositionRecognizer = [[MapGestureRecognizer alloc] init];
changeMapPositionRecognizer.touchesEndedCallback = ^(NSSet * touches, UIEvent * event)
{
...
};
[self.mapView addGestureRecognizer:changeMapPositionRecognizer];
[changeMapPositionRecognizer release];
}
Run Code Online (Sandbox Code Playgroud)
MapGestureRecognizer.h的代码:
#import <UIKit/UIKit.h>
typedef void (^TouchesEventBlock) (NSSet * touches, UIEvent * event);
@interface MapGestureRecognizer : UIPinchGestureRecognizer
@property(nonatomic, copy) TouchesEventBlock touchesEndedCallback;
@end
Run Code Online (Sandbox Code Playgroud)
MapGestureRecognizer.m的代码:
#import "MapGestureRecognizer.h"
@implementation MapGestureRecognizer
@synthesize touchesEndedCallback = _touchesEndedCallback;
- (id)init
{
self = [super …
Run Code Online (Sandbox Code Playgroud) 编辑:将标题从“双击..”更改为“双击选择触摸..”
我需要在我的应用程序中检测至少对 MKPinAnnotationView 的第二次触摸。目前我能够获得第一次触摸(我从这里使用 kvo:Detecting when MKAnnotation is selected in MKMapView),并且它在第一次触摸时效果很好),但是如果我再次点击引脚,则不会调用任何内容,因为所选值不会改变。我尝试使用自 ios 4 以来有效的“mapView:didSelectAnnotationView:”进行相同的操作,但在第二次点击时也不会再次调用它。
如果有人能帮助我解决这个问题,那就太好了!
此致
编辑,添加更多信息:
因此,触摸不必很快,如果用户触摸图钉,我会在注释的标题和副标题中显示一条消息,如果用户再次触摸同一个图钉,所以我会用它做另一件事
iphone mkpinannotationview mkannotation mkannotationview ios
iphone ×9
mkmapview ×7
ios ×5
objective-c ×4
mapkit ×2
mkannotation ×2
mkpolyline ×2
touch-event ×2
cocoa-touch ×1
events ×1
fbconnect ×1
ios4 ×1
multi-touch ×1
overlay ×1
pinch ×1
touches ×1
uitableview ×1
zoom ×1