我已经创建了一个UIScrollView
,现在尝试在 ScrollView 上放置一个UIButton
。但是,当我构建并运行应用程序时, ScrollView 仍然可以正常工作,但我看不到 UIButton
。
我在界面构建器中链接了UIButton IBOutlet
。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.delegate = self;
scrollView.bounces = NO;
backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"auckland-300.jpg"]];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
// Note here you should size the container view appropriately and layout backgroundImage and image accordingly.
containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,601,601)];
playButton = [[UIButton alloc] init]; //test button cannot see it.
[containerView addSubview:backgroundImage];
[containerView addSubview:image];
scrollView.contentSize = containerView.frame.size;
[scrollView addSubview:containerView];
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 31.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
self.view = scrollView;
}
如有任何帮助,我们将不胜感激
最佳答案
一切似乎都很好。但我认为您看不到按钮 playButton
的原因是您没有将其添加到 view
本身。
你不需要这样做吗? [containerView addSubview:playButton];
为了帮助您,这是我进行调试的方法 -
UIView implements a useful description method. In addition, it implements a recursiveDescription method that you can call to get a summary of an entire view hierarchy.
NSLog(@"%@", [controller.view recursiveDescription]);
关于iphone - UIScrollView覆盖UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8455288/