UIControl touchEvent

时间:2010-10-12 06:20:57

标签: uiimageview uiimage uicontrol touch-event

我实现了以下viewDidLoad()方法:

- (void)viewDidLoad {
    [super viewDidLoad];

    // loading images into the queue
    loadImagesOperationQueue = [[NSOperationQueue alloc] init];
    AFOpenFlowView *openFlow = self.view;
    theControl = [[UIControl alloc] initWithFrame:self.view.frame];
    NSString *imageName;
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10, 10, 40, 40);
    [btn addTarget:self action:@selector(testMethode) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"<<" forState:UIControlStateNormal];
    [btn setHidden:YES];
    [theControl addSubview:btn];

    for (int i=0; i < 10; i++) {
        imageName = [[NSString alloc] initWithFormat:@"cover_%d.jpg", i];
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
        UIImage *aktuellesImage = imageView.image;
        UIImage *scaledImage = [aktuellesImage scaleToSize:CGSizeMake(100.0f, 100.0f)];
        [openFlow setImage:scaledImage forIndex:i];
//      [(AFOpenFlowView *)self.view setImage:scaledImage forIndex:i];

        [imageName release];
        [aktuellesImage release];       
    }
    [theControl addSubview:openFlow];
    [theControl setUserInteractionEnabled:YES];

    [(AFOpenFlowView *)self.view setNumberOfImages:10];
}

以下touchesEnded()方法:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [btn setHidden:NO];
}

但是touchesEnded不起作用,当我触摸图片时按钮不会显示,是否有人知道问题是什么?

问候Marco

1 个答案:

答案 0 :(得分:0)

确保您的视图启用了用户互动,以便注册触摸。这可以在View Controller中进行设置:

self.view.userInteractionEnabled = YES;