【问题标题】:Add button over subview which is again over a superview在子视图上添加按钮,该子视图再次位于超级视图上
【发布时间】:2016-10-12 06:44:53
【问题描述】:

我有 uiviewController 作为主视图,然后我添加了名为“supporteview”的子视图。现在我在 supportview 上以编程方式添加按钮。 由于某种原因,按钮不可见,但是当我在主视图上加载按钮时,我可以看到按钮。

[self.view addSubview:self.supportview]; [self.view bringSubviewToFront:self.supportView]; [self.supportView addSubview:self.btn]; [self.supportView bringSubviewToFront:self.button];

我在 supportView 中添加了滑块,然后加载按钮。

【问题讨论】:

  • 你是动态生成按钮还是在storyboard里面?
  • 动态生成。
  • 尝试更新按钮的框架。将 x 和 y 原点设置为按钮框架的 0。
  • 看我以这种方式添加框架。浮动 xCordPerTimeStamp = SLIDER_WIDTH/self.slider.maximumValue;浮动 xcord = [playbyplay.GameTime floatValue] * 60; int finalx =(xCordPerTimeStamp *xcord) + startxoffset + XORIGIN; int finaly = 700; NSLog(@"final x is %d",finalx); if([playbyplay.Opponent isEqualToString:@"B"]) { finaly = 740; } NSLog(@"final x is %d and y%d",finalx,finaly); btn.frame = CGRectMake(finalx, finaly, 3, 8);

标签: ios uiview uibutton subview addsubview


【解决方案1】:

尝试将第一个按钮添加到 supportView,然后将 supportView 添加到您的视图。您还可以使用视图检查器查看按钮在哪里https://www.raywenderlich.com/98356/view-debugging-in-xcode-6

这将帮助您在运行时检查框架和约束

【讨论】:

  • Supportview 已添加到情节提要中,并且在事件中我正在通过 supportview 生成按钮。
  • 那么你不需要下面的行 [self.view addSubview:self.supportview]; [self.view bringSubviewToFront:self.supportView];只需在 supportView 上添加按钮
  • 但没有显示
  • 可以试试查看调试吗? developer.apple.com/library/ios/documentation/ToolsLanguages/…,很简单,帮你在运行时查看视图和框架
  • 或者尝试将supportView的背景颜色设置为红色或绿色(只是为了测试),可能是它的约束设置不正确。
猜你喜欢
  • 1970-01-01
  • 2016-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-09
相关资源
最近更新 更多