为什么当我删除子视图时我的视图会变成白色?

发布于 2024-11-14 06:09:00 字数 811 浏览 1 评论 0原文

在我看来,我有一个滚动视图作为子视图。滚动视图有另一个子视图,称为 PDFView。它用于显示 PDF 页面。
该视图有 2 个子视图。 drawImage 是从磁盘加载到整个 PDF 视图上方的图像。
PaintView 是第二个子视图,所有绘画和标记都在其中完成。 但我只想在按下绘画按钮时添加paintView。
这有效,但是当我再次按下它以停止绘画模式并从超级视图中删除视图时,整个屏幕会变白。
我怎样才能绕过它?

- (id)init
{
  ...
  [self.view addSubview:theScrollView];
  [theScrollView addSubview:thePDFView];

  drawImage = [UIImage imageWithData:retrievedData];
  [thePDFView addSubview:drawImage];

  paintView = [[PaintViewController alloc] initWithImage:drawImage andPath:pageString];
}

- (void) togglePainting:(NSNotification *)notif  {

if (!painting) {
    theScrollView.scrollEnabled = false;
    [thePDFView addSubview:paintView.view];
}
else {
    theScrollView.scrollEnabled = true;
    [thePDFView removeFromSuperview];
}

painting = !painting;
}

in my view I have a scrollView as subview. The scrollView has another subview called thePDFView. It is for showing a PDF page.
This view has 2 subviews. drawImage is an image loaded from disk above the whole PDF view.
And paintView is the second subview where all the painting and markup is done.
But I only want to add paintView when I press the paint Button.
This works, but when I press it again to stop painting mode and remove the view from superview, the whole screen gets white.
How can I bypass that?

- (id)init
{
  ...
  [self.view addSubview:theScrollView];
  [theScrollView addSubview:thePDFView];

  drawImage = [UIImage imageWithData:retrievedData];
  [thePDFView addSubview:drawImage];

  paintView = [[PaintViewController alloc] initWithImage:drawImage andPath:pageString];
}

- (void) togglePainting:(NSNotification *)notif  {

if (!painting) {
    theScrollView.scrollEnabled = false;
    [thePDFView addSubview:paintView.view];
}
else {
    theScrollView.scrollEnabled = true;
    [thePDFView removeFromSuperview];
}

painting = !painting;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫尐诺 2024-11-21 06:09:00
[thePDFView removeFromSuperview]; 

删除滚动视图内的整个视图,只留下现在没有任何子视图的滚动视图。因此你的观点是白色的。我认为您只想删除 paintView.view 所以它应该是 [paintView.view removeFromSuperview];

[thePDFView removeFromSuperview]; 

removes the whole view which was inside the scroll view leaving you nothing but the scrollview which does not have any subviews now. Hence your view is white. I think you wanted to remove only paintView.view so it should be [paintView.view removeFromSuperview];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文