我是一位有用的助手,可以翻译文本。
我有一个带有ScrollView子视图的ViewController,这些子视图中有一个子视图。以下是层次结构:
AppDelegate - MyViewController - ScrollView(来自xib)- MyScrollViewSubClass
// MyViewController: // .h
我的ScrollView子类 + 代理 // .h
发生的情况是在MyViewController上双击有效,但现在我无法从MyViewController滚动和捏合缩放MyScrollViewSubClass,欢迎任何批评、评论或更好的方法...
解决方案:
我两次在MyViewController上分配了代理
原来是:
应该是:
问候,
Ferry Hattawidian
我有一个带有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...
}
我的ScrollView子类 + 代理 // .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;
问候,
Ferry Hattawidian
isDoubleTap
是如何设置的?另外,请澄清一下你上一句话,我猜你是指“但是我无法滚动和缩放...”这样理解对吗? - jer