【问题标题】:UIScrollView covers UIButtonUIScrollView 覆盖 UIButton
【发布时间】:2012-01-17 07:46:17
【问题描述】:

我创建了一个UIScrollView,现在正尝试在滚动视图上放置一个UIButton。但是,当我构建并运行应用程序时,滚动视图仍然可以正常工作,但我看不到 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;    
}

任何帮助将不胜感激

【问题讨论】:

  • 你想在 in scrollView 或 above scrollView 中添加 UIButton?
  • 在滚动视图上方,所以我仍然可以在不影响按钮的情况下进行缩放和滚动。

标签: iphone ios uiscrollview uibutton iboutlet


【解决方案1】:

按钮可能在您将控制器视图链接到的笔尖中,对吧?通过将滚动视图分配给视图,您可以从 控制器的笔尖,这就是为什么你看不到或按下它的原因。

您可以将按钮放在滚动视图中,也可以同时添加滚动视图和播放按钮作为 self.view 的子视图。

也许您想重新考虑您的设计。 在滚动视图上放置一个按钮对我来说似乎并不是一个好习惯。

【讨论】:

  • 好的,谢谢,目前该按钮用于稍后测试我想要一个透明图像播放并停止在滚动视图等内播放动画。
【解决方案2】:

一切似乎都很好。但我认为您看不到按钮 playButton 的原因是您没有将其添加到 view 本身。

你不需要这样做吗? [containerView addSubview:playButton];

为了帮助你,这是我为调试所做的 -

UIView 实现了一个有用的描述方法。此外,它 实现一个 recursiveDescription 方法,您可以调用该方法来获取 整个视图层次结构的摘要。

NSLog(@"%@", [controller.view recursiveDescription]);

【讨论】:

  • Hrmm.. 仍然表现得很有趣。我最真实地使用 slog 但控制器有问题.. 所以现在研究一下。
  • 好的,但是它可以与程序化设计的按钮一起使用。当我把它放到同一个视图中时,它也会缩放。所以现在我想弄清楚如何让它出现在上面。也许是另一个视图或其他东西。
  • 是的,可以。另外,如果此答案有帮助,请考虑接受此答案...谢谢
猜你喜欢
  • 1970-01-01
  • 2015-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
相关资源
最近更新 更多