UIControl touchEvent
Posted
技术标签:
【中文标题】UIControl 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不起作用,当我触摸图片时按钮不会显示,有人知道是什么问题吗???
问候马可
【问题讨论】:
【参考方案1】:确保您的视图启用了用户交互以注册触摸。这可以在您的视图控制器中设置:
self.view.userInteractionEnabled = YES;
【讨论】:
以上是关于UIControl touchEvent的主要内容,如果未能解决你的问题,请参考以下文章