【发布时间】:2010-12-12 03:33:25
【问题描述】:
我有一个带有 ScrollView 子视图的 ViewController,这些子视图中有一个子视图,下面是层次结构:
AppDelegate - MyViewController - ScrollView(来自 xib) - MyScrollViewSubClass
// MyViewController : // .h
@interface MyViewController : UIViewController<MyScrollViewSubClassDelegate,UIScrollViewDelegate> {
UIScrollView *scrollView; // Loaded from xib
}
@property(nonatomic,retain) IBOutlet UIScrollView *scrollView;
@end
// .m
@implementation MyViewController
@synthesize scrollView;
- (void)viewDidLoad {
[super viewDidLoad];
scrollView.delegate = self;
MyScrollViewSubClass *myScrollView = [[MapScrollView alloc] init];
myScrollView.delegate = self;
myScrollView.myDelegate = self;
scrollView addSubview:mapScrollView];
}
// The MyScrollViewSubClassDelegate @required method
- (void) onDoubleTapLocation: (CGPoint)tapPoint
{
// Working,,,NSLog shown that this line is Working...
}
// MyScrollViewSubClass + 委托 // .h
// Protocol
@protocol MyScrollViewSubClasswDelegate <NSObject>
@required
- (void) onDoubleTapLocation: (CGPoint)tapPoint;
@end
//Interface
@protocol MyScrollViewSubClass;
@interface MyScrollViewSubClass : UIScrollView <UIScrollViewDelegate> {
id <MyScrollViewSubClasswDelegate> myDelegate;
// Another vars..
}
@property (nonatomic,assign) id<MyScrollViewSubClasswDelegate> myDelegate;
- (void)handleDoubleTap;
@end
// .m
@implementation MyScrollViewSubClass
@synthesize myDelegate;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
// Another Code Here...
self.delegate = self; // delegate for UIScrollView
self.myDelegate = self;
//Another Code Here...
}
return self;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(isDoubleTap)
{
//Call handle double tap
[self handleDoubleTap];
}
}
- (void)handleDoubleTap {
[self.myDelegate onDoubleTapLocation: tapLocation];
}
双击正在 MyViewController 上工作,但现在我无法从 MyViewController 滚动和捏缩放 MyScrollViewSubClass,欢迎任何批评、评论或更好的方法..
已解决:
我在 MyViewController 上分配了两次委托
是:
myScrollView.delegate = self;
myScrollView.myDelegate = self;
应该是:
myScrollView.myDelegate = self;
问候,
哈达威迪安渡轮
【问题讨论】:
-
isDoubleTap是怎么设置的?另外,澄清你的最后一句话,我怀疑你的意思是“但我不能滚动和捏我的……”是准确的吗? -
是的,这是我的错字..我通过计算触摸来检查触摸是双击还是单击 --> if ([touches count] == 2) { isDoubleTap = YES;}跨度>
标签: iphone delegates uiscrollview protocols touch