p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #929292}
TapDetectingWindow.h
//
// plist>
// NBFisheryiPad
//
// Created by shiqyn on 11-6-16.
// Copyright 2011 Stongsoft. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol TapDetectingWindowDelegate<NSObject>
- (void)userDidTapObserveView:(id)tapPoint;
@end
@interface TapDetectingWindow : UIWindow {
UIView *viewToObserve;
id <TapDetectingWindowDelegate> controllerThatObserves;
}
@property (nonatomic, retain) UIView* viewToObserve;
@property (nonatomic, assign) id <TapDetectingWindowDelegate> controllerThatObserves;
@end
TapDetectingWindow.m
//
// plist>
// NBFisheryiPad
//
// Created by shiqyn on 11-6-16.
// Copyright 2011 Stongsoft. All rights reserved.
//
#import "TapDetectingWindow.h"
@implementation TapDetectingWindow
@synthesize viewToObserve;
@synthesize controllerThatObserves;
- (id)initWithViewToObserver:(UIView *)view andDelegate:(id)delegate {
if(self == [super init]) {
self.viewToObserve = view;
self.controllerThatObserves = delegate;
}
return self;
}
- (void)dealloc {
[viewToObserve release];
[super dealloc];
}
- (void)forwardTap:(id)touch
{
[controllerThatObserves userDidTapObserveView:touch];
}
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
if (viewToObserve == nil || controllerThatObserves == nil)
return;
NSSet *touches = [event allTouches];
if (touches.count != 1)
return;
UITouch *touch = touches.anyObject;
if (touch.phase != UITouchPhaseEnded)
return;
if ([touch.view isDescendantOfView:viewToObserve] == NO)
return;
CGPoint tapPoint = [touch locationInView:viewToObserve];
NSArray *pointArray = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%f", tapPoint.x],
[NSString stringWithFormat:@"%f", tapPoint.y], nil];
if (touch.tapCount == 1)
{
[self performSelector:@selector(forwardTap:) withObject:pointArray afterDelay:0];
}
else if (touch.tapCount > 1)
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(forwardTap:) object:pointArray];
}
}
@end
用法:
1.双击MainWindow.xib, 弹出的Window,按control+2,弹出的window attributes窗口中 将class identity设置成TapDetectingwindow.
2.在要使用TapDetectingwindow类中添加如下代码:
TapDetectingWindow* tapDetectWindow = ((TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0]);
tapDetectWindow.viewToObserve = mapView;
tapDetectWindow.controllerThatObserves = self;
并实现delegate:
#pragma mark TapDetectingWindowDelegate
- (void)userDidTapObserveView:(id)tapPoint
{
DLog(@">>>userDidTapObserveView");
[self hideSearchRangeSlider];
}
分享到:
相关推荐
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) calloutView.addSubview(button) ``` 2. 为按钮添加响应方法: ```swift @objc func buttonTapped(sender: UIButton) { print(...
11. **用户交互**:用户可能会通过滑动、缩放地图来寻找房源,因此需要处理地图的拖动、缩放手势,以及点击标注后的响应事件。 12. **数据持久化**:如果应用需要存储大量的房源信息,可以考虑使用CoreData或SQLite...
10. **手势识别与响应**: 如UITapGestureRecognizer、UIPanGestureRecognizer等,实现用户界面的触摸事件处理。 11. **地图服务和定位API**: 如使用MKMapView集成地图功能,以及CLLocationManager获取设备位置信息...
7. **用户交互**:为了响应用户的触摸事件,例如点击地图上的标记,MapTestApp会使用手势识别器和委托方法来实现交互逻辑。 8. **Storyboard和Auto Layout**:Xcode中的Storyboard文件用于设计和布局UI界面,而Auto...
- **单元格选择**:响应用户的触摸事件,实现单元格选择功能。 - **单元格删除**:通过Swipe-to-delete手势来删除单元格。 - **UIAlertController**:创建和显示各种类型的对话框。 #### 十一、导航控制器与Segue ...
伦斯勒班车(Rensselaer-Shuttle)是一款专为iPhone、iPad、iPod touch、Apple Watch以及Mac用户设计的应用程序,旨在方便用户实时追踪伦斯勒理工学院(Rensselaer Polytechnic Institute)的校园班车动态。...