第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何攔截觸摸MKMapView或UIWebView對(duì)象上的事件?

如何攔截觸摸MKMapView或UIWebView對(duì)象上的事件?

蕪湖不蕪 2019-07-23 18:01:54
如何攔截觸摸MKMapView或UIWebView對(duì)象上的事件?我不確定我做錯(cuò)了什么,但我試圖抓住一個(gè)MKMapView物體。我通過(guò)創(chuàng)建以下類(lèi)來(lái)繼承它:#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>@interface MapViewWithTouches : MKMapView {}- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event;   @end并實(shí)施:#import "MapViewWithTouches.h"@implementation MapViewWithTouches- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {     NSLog(@"hello");     //[super touchesBegan:touches   withEvent:event];}@end但看起來(lái)當(dāng)我使用這個(gè)類(lèi)時(shí),我在控制臺(tái)上看不到任何內(nèi)容:MapViewWithTouches *mapView = [[MapViewWithTouches alloc] initWithFrame:self.view.frame];[self.view insertSubview:mapView atIndex:0];知道我做錯(cuò)了什么嗎?
查看完整描述

3 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

我發(fā)現(xiàn)實(shí)現(xiàn)這一目標(biāo)的最好方法是使用手勢(shì)識(shí)別器。其他方式涉及大量的hackish編程,不完美地復(fù)制Apple的代碼,特別是在多點(diǎn)觸控的情況下。

這就是我所做的:實(shí)現(xiàn)一個(gè)無(wú)法阻止的手勢(shì)識(shí)別器,并且無(wú)法阻止其他手勢(shì)識(shí)別器。將它添加到地圖視圖,然后使用gestureRecognizer的touchesBegan,touchesMoved等等。

如何檢測(cè)MKMapView中的任何水龍頭(沒(méi)有技巧)

WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];tapInterceptor.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
        self.lockedOnUserLocation = NO;};[mapView addGestureRecognizer:tapInterceptor];

WildcardGestureRecognizer.h

////  WildcardGestureRecognizer.h//  Copyright 2010 Floatopian LLC. All rights reserved.//#import <Foundation/Foundation.h>typedef void (^TouchesEventBlock)(NSSet * touches, UIEvent * event);@interface WildcardGestureRecognizer : UIGestureRecognizer {
    TouchesEventBlock touchesBeganCallback;}@property(copy) TouchesEventBlock touchesBeganCallback;@end

WildcardGestureRecognizer.m

////  WildcardGestureRecognizer.m//  Created by Raymond Daly on 10/31/10.//  Copyright 2010 Floatopian LLC. All rights reserved.//#import "WildcardGestureRecognizer.h"@implementation WildcardGestureRecognizer@synthesize touchesBeganCallback;-(id) init{
    if (self = [super init])
    {
        self.cancelsTouchesInView = NO;
    }
    return self;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    if (touchesBeganCallback)
        touchesBeganCallback(touches, event);}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{}- (void)reset{}- (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event{}- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer{
    return NO;}- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer{
    return NO;}@end

SWIFT 3

let tapInterceptor = WildCardGestureRecognizer(target: nil, action: nil)tapInterceptor.touchesBeganCallback = {
    _, _ in
    self.lockedOnUserLocation = false}mapView.addGestureRecognizer(tapInterceptor)

WildCardGestureRecognizer.swift

import UIKit.UIGestureRecognizerSubclassclass WildCardGestureRecognizer: UIGestureRecognizer {

    var touchesBeganCallback: ((Set<UITouch>, UIEvent) -> Void)?

    override init(target: Any?, action: Selector?) {
        super.init(target: target, action: action)
        self.cancelsTouchesInView = false
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
        super.touchesBegan(touches, with: event)
        touchesBeganCallback?(touches, event)
    }

    override func canPrevent(_ preventedGestureRecognizer: UIGestureRecognizer) -> Bool {
        return false
    }

    override func canBePrevented(by preventingGestureRecognizer: UIGestureRecognizer) -> Bool {
        return false
    }}


查看完整回答
反對(duì) 回復(fù) 2019-07-23
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

經(jīng)過(guò)一天的比薩餅,尖叫聲,我終于找到了解決方案!井井有條!

Peter,我使用了上面的技巧并稍微調(diào)整了一下,最終得到了一個(gè)與MKMapView完美配合的解決方案,并且也應(yīng)該與UIWebView配合使用

MKTouchAppDelegate.h

#import <UIKit/UIKit.h>@class UIViewTouch;@class MKMapView;@interface MKTouchAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UIViewTouch *viewTouch;
    MKMapView *mapView;}@property (nonatomic, retain) UIViewTouch *viewTouch;@property (nonatomic, retain) MKMapView *mapView;@property (nonatomic, retain) IBOutlet UIWindow *window;@end

MKTouchAppDelegate.m

#import "MKTouchAppDelegate.h"#import "UIViewTouch.h"#import <MapKit/MapKit.h>@implementation MKTouchAppDelegate@synthesize window;@synthesize viewTouch;@synthesize mapView;- (void)applicationDidFinishLaunching:(UIApplication *)application {

    //We create a view wich will catch Events as they occured and Log them in the Console
    viewTouch = [[UIViewTouch alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

    //Next we create the MKMapView object, which will be added as a subview of viewTouch
    mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [viewTouch addSubview:mapView];

    //And we display everything!
    [window addSubview:viewTouch];
    [window makeKeyAndVisible];}- (void)dealloc {
    [window release];
    [super dealloc];}@end

UIViewTouch.h

#import <UIKit/UIKit.h>@class UIView;@interface UIViewTouch : UIView {
    UIView *viewTouched;}@property (nonatomic, retain) UIView * viewTouched;- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;- (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;@end

UIViewTouch.m

#import "UIViewTouch.h"#import <MapKit/MapKit.h>@implementation UIViewTouch@synthesize viewTouched;//The basic idea here is to intercept the view which is sent back as the firstresponder in hitTest.//We keep it preciously in the property viewTouched and we return our view as the firstresponder.- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    NSLog(@"Hit Test");
    viewTouched = [super hitTest:point withEvent:event];
    return self;}//Then, when an event is fired, we log this one and then send it back to the viewTouched we kept, and voilà!!! :)- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Began");
    [viewTouched touchesBegan:touches withEvent:event];}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Moved");
    [viewTouched touchesMoved:touches withEvent:event];}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Ended");
    [viewTouched touchesEnded:touches withEvent:event];}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Cancelled");}@end

我希望這對(duì)你們有所幫助!

干杯


查看完整回答
反對(duì) 回復(fù) 2019-07-23
?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleGesture:)];   tgr.numberOfTapsRequired = 2;tgr.numberOfTouchesRequired = 1;[mapView addGestureRecognizer:tgr];[tgr release];- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer{
    if (gestureRecognizer.state != UIGestureRecognizerStateEnded)
        return;

    CGPoint touchPoint = [gestureRecognizer locationInView:mapView];
    CLLocationCoordinate2D touchMapCoordinate = [mapView convertPoint:touchPoint toCoordinateFromView:mapView];

    //.............}


查看完整回答
反對(duì) 回復(fù) 2019-07-23
  • 3 回答
  • 0 關(guān)注
  • 671 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)