【问题标题】:UIControl touchEventUIControl touchEvent
【发布时间】:2010-10-12 06:20:56
【问题描述】:

我已经实现了以下 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不起作用,当我触摸图片时按钮不会显示,有人知道是什么问题吗???

问候马可

【问题讨论】:

    标签: uiimageview uiimage uicontrol touch-event


    【解决方案1】:

    确保您的视图启用了用户交互以注册触摸。这可以在您的视图控制器中设置:

    self.view.userInteractionEnabled = YES;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 2017-11-17
      • 2013-02-24
      相关资源
      最近更新 更多