【发布时间】:2013-12-12 15:26:00
【问题描述】:
有必要创建一个 UIButton 的子类,我们称之为 subButton。这些 subButton 被一一实例化并动态添加到 UIScrollView 对象中。
不幸的是,子按钮没有按预期做出反应。滚动离开第一个动态生成的子按钮后,然后返回它们。他们失去了对单击的反应。我无法解释这种行为。有人可以解释为什么它会这样吗?
非常感谢。
源代码
self.subButton = [[SubButton alloc]initWithFrame:CGRectMake(69.5, y, 201, 114)];
[self.subButton setBackgroundColor:[UIColor blueColor]];
self.subButton.imageData = imageData;
self.subButton.videoPath = videoPath;
self.subButton.vidIndex = _indexVideo +1;
[self.subButton drawVidPreview];
[self.subButton setTag:(_indexVideo +1)];
[self.subButton addTarget:self action:@selector(handleSingleTap:) forControlEvents:UIControlEventTouchUpInside];
[self.videoScroll addSubview:self.subButton];
[_videoPreviews addObject:self.subButton];
subButton 方法 drawVidPreview 将一些子视图添加到自身。
【问题讨论】:
-
可以添加按钮的代码吗?
标签: ios dynamic uiscrollview uibutton subclassing