iphone - UIScrollView覆盖UIButton

标签 iphone ios uiscrollview uibutton iboutlet

我已经创建了一个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/

相关文章:

ios - UIDocumentInteractionController 操作/选项菜单在首次启动时不可见

ios - 当我在 iphone 5 屏幕上运行程序时 xcode 看起来像 iphone 4

ios - Objective-C - 具有特定子字符串的 NSRegularExpression

ios 将 UIScrollView 滚动条颜色更改为不同的颜色

ios - 我需要使我的 UIImageView 适合我的 UIScrollView 而无需平移。 [iOS]

iphone - 如何在 UIScrollView 中进行垂直分页

iphone - 使用 UIImagePickerController 偷偷录制电影

iphone - AVAudioRecorder 不会在设备上录制

ios - RLM 异常 : 'Primary key property ' serial' does not exist on object 'Book' Migrating to Swift 4

ios - 在函数中调用 IBOutlet 属性时获得 Nil