1

所以我读了很多,但我仍然找不到解决方案。

我有 aUIViewController正在创建(以编程方式) a UIScrollView,它包含 aUIView和 a UIImage。谎言凌驾于其他UIView之上。

这会UIView产生一些UIImageViews我需要在被点击时获得反馈的信息。我需要通过获取他们的标签来知道哪个图像被点击了。这就是为什么我不能使用手势识别器,因为它只能在一个视图上调用。

如果我这样称呼:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    NSLog(@"tag=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);

}

在视图上(称为GraphView,它有自己的类)我得到了我需要的东西。不过,我需要从ViewController端执行此操作,因为我必须打开模式窗口、导航控制器等……如果我在ViewController上使用相同的代码,则不会发生任何事情。如果我禁用用户交互,UIScrollView它就可以工作。如果我禁用延迟,UIScrollView什么都不会发生。不管你按多久,你什么都得不到。touchesBegan即使启用了延迟,也不会被调用。

这是我生成视图的ViewController实现的一部分:

// ScrollView
CGRect frame = CGRectMake(0, 0, 480, 320);
myScrollView = [[UIScrollView alloc] initWithFrame:frame];
myScrollView.backgroundColor = [UIColor blackColor];
myScrollView.showsVerticalScrollIndicator = YES;
myScrollView.showsHorizontalScrollIndicator = YES;
myScrollView.userInteractionEnabled = YES;
myScrollView.contentSize = CGSizeMake(SCROLLVIEW_WIDTH, SCROLLVIEW_HEIGHT);
myScrollView.delegate = self;
[self.view addSubview:myScrollView];

// Add UIImage for background
UIImageView *backgroundGraph = [[UIImageView alloc] initWithFrame:CGRectMake (0,0,SCROLLVIEW_WIDTH,SCROLLVIEW_HEIGHT)];
backgroundGraph.image = [UIImage imageNamed:@"graph_background.png"];
backgroundGraph.userInteractionEnabled = YES;
[myScrollView addSubview:backgroundGraph];
//[self.view addSubview:backgroundGraph];
[backgroundGraph release];

// Add View for Graph.
GraphView *graphViewC = [[GraphView alloc] init];
self.graphView = graphViewC;
graphView.tag = 200;
graphView.userInteractionEnabled = YES;
graphView.frame = CGRectMake(0, 0, SCROLLVIEW_WIDTH, SCROLLVIEW_HEIGHT);
graphView.backgroundColor = [UIColor clearColor];
[myScrollView addSubview:graphView];
//[self.view addSubview:graphView];

ViewController上的.h文件如下所示:

#import <UIKit/UIKit.h>

@class GraphView;

@interface TrackingViewController : UIViewController <UIScrollViewDelegate> {
    UIScrollView *myScrollView;

    GraphView *graphView;

    int someNum;

#define SCROLLVIEW_HEIGHT 273
#define SCROLLVIEW_WIDTH 599

}

@property (nonatomic, retain) GraphView *graphView;

- (void) openModal;
//- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer;

@property (nonatomic, retain) UIScrollView *myScrollView;

@end

与往常一样,我感谢所有可以提供任何想法的人(我一直在这里得到很多帮助,所以提前感谢:-))。

4

0 回答 0