问题标签 [superview]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
8574 浏览

ios - 子视图访问superview

我有一个带有内容视图的滚动视图,最后是内容视图的子视图。我想停止[scrollView scrollEnabled:NO]从子视图滚动。我可以了解方法吗?

0 投票
4 回答
8847 浏览

objective-c - 如何在 Superview 的视图中插入视图?(iOS)

我有下面的代码行......我将如何修改它以将子视图插入名为“foo”的超级视图的视图中?

0 投票
2 回答
611 浏览

ios - 尝试从超级视图中删除对象时,Objective-c 程序崩溃

波纹管是我按下按钮时调用的代码。该按钮将调用下面的方法。但是我收到“发送到实例的无法识别的选择器”错误。我究竟做错了什么?在调用此方法之前,已在另一种方法中声明了对象。我也试过隐藏按钮,但它们也会崩溃。有人请帮忙。

崩溃是:

[buttCheck removeFromSuper]; 行上的线程 1:EXC_BAD_ACCESS"

-[__NSCFDictionary removeFromSuperview]:无法识别的选择器发送到实例 0x686b020 2012-06-24 19:08:12.175 HeadsUp[59630:f803] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFDictionary removeFromSuperview]:无法识别的选择器发送到实例 0x686b020'

0 投票
1 回答
1458 浏览

ios - 如何检查 UIView 是否仍然存在?

我必须根据设备方向为 UIView 设置一些自定义大小参数。我加载没有自己的视图控制器的 UIView,如下所示:

在 main.h

在 main.m

. . .

如果不再需要,我将其从超级视图中删除

删除后日志显示 (null)

我喜欢这样的尺寸调整

到目前为止工作正常,直到我不从我的主视图中删除子视图(socialAcitonView)。导致之后 self.socialActionView 不再可访问。我在stackoverflow上看到了很多例子,比如

或者

或者

或者

但它们都不起作用。调试器总是抛出异常导致错误访问。什么(从我的角度来看)意味着该对象不再存在。但是在我从超级视图中删除它并说(null)之后,记录器如何访问它?

我知道最好给视图一个专用的视图控制器并将 didRotateFromInterfaceOrientation 放在那里,这样我就不必检查 socialActionView 是否在那里。无论如何,我想问一下是否有办法检查 UIView 是否为(null)。在我将所有代码更改为视图/视图控制器对之前。

任何提示表示赞赏!

0 投票
1 回答
585 浏览

objective-c - 视图控制器第二次启动后,Superview 为 Nil

我已经花了几个小时,我无法弄清楚这一点。我有一个在此处启动的详细视图控制器(UITableView):

在详细视图控制器中有一个按钮方法,它调用下面的方法来显示一个滑入滑出动画来确认用户的选择:

}

ConfirmActionViewController 调用的协议方法,表示动画完成。

这在我第一次按下按钮时效果很好。如果我弹出细节控制器并将其推回堆栈并再次按下按钮,则不会发生任何事情,并且此后每次调用该方法时,细节控制器的超级视图都为零。细节视图的方法中的superview不是nil viewWillAppear,只有当它到达confirmLastActionWithMessage方法时。两者之间不会发生其他用户交互。如何找回超级视图?我有一个没有动画的类似代码。

我还注意到,从堆栈中弹出时,详细视图控制器没有调用 dealloc。不确定问题出在哪里。

谢谢。

编辑 1

好的。我用这个替换了 addSubview 行:

[self.view insertSubview:self.confirmActionViewController.view atIndex:0];

并且动画视图出现在其中一个表格单元格的下方。表格单元之一可以窃取超级视图吗?

0 投票
1 回答
78 浏览

iphone - 转换其容器时显示子视图

从一个视图控制器转换到另一个视图控制器时,是否可以为当前容器中的子视图设置动画,使其在顶部停留片刻,然后在转换完成后将其放置到新容器上。

要理解我的意思,请尝试从 iOS <5 中的照片应用通过电子邮件发送照片。照片在顶部停留片刻,然后放置在邮件编辑器中。就我而言,从一个容器过渡到另一个容器时,我想要相同的效果。

0 投票
3 回答
14022 浏览

ios - iOS:检测我的 UIView 何时添加到其他视图中

当我的 CustomView 类被添加到其他视图中或我的超级视图发生变化时,我需要检测它。

0 投票
6 回答
4284 浏览

ios - black screen - superview is nil in viewWillAppear

I have an application created from the tabbed application template. (ARC, iOS 4)

  • There are several tabs and there is a button on the 2. tabs viewcontroller.view(ViewCont2).
  • This button loads another viewcontroller's(ModalViewCont) view by presentModalViewController method.
  • There is a close button on ModalViewCont which calls dismissModalViewControllerAnimated.
  • In viewDidDisappear of ViewCont2, i am setting self.view = nil and other outlets to nil to unload the view so it will be fresh loaded next time it appears on screen. I am doing this because it inherits from a base class(BaseViewCont) which initializes some general properties of the view controller and adds some buttons, labels etc. in viewDidLoad method. So, ViewControllers that inherit from this base class may configure those properties differently as they wish in their viewDidLoad method.

Problem

Now, when ModalViewCont on screen, pressing the Home button to put application in background and after getting the application back, closing the ModalViewCont does not bring back the ViewCont2's view but a black screen with the tabbar at the bottom. The same thing happens without putting the application background/foreground; if other tabs tapped before tapping the 2. tab.(EDIT : This happens only if self.view set to nil in viewWillDisappear instead of viewDidDisappear.)

I determined that ViewCont2 loads a new view (checked it's reference) but view's superview is nil so the new view is not displayed but a black screen.

Things that did not work

  • Using [self.view removeFromSuperview]; before setting self.view=nil,
  • In viewWillAppear adding view to the parent; [self.parentViewController.view addSubview:self.view]; This one did not work smoothly, view placed slightly up of the screen. This is because there are several other superviews in the hierarchy.

Solutions i considered;

  • 1- If superview is nil in viewDidLoad, it becomes available in viewWillAppear (assumption). So, viewWillAppear method of ViewCont2 could be used to get the superview loaded correctly by the following;

_

  • 2- viewWillAppear method of base class could be used instead for initialization so there is no need to unload the view. So, performance could be optimized, it will not be unloaded each time view disappears. Also, it would be better to perform initialization only once by checking a flag, instead of performing it every time it appears.

Questions

  • 1- Why does not the superview restored? What should i do for it? (This is the main problem i want to understand and solve instead of trying alternatives...)
  • 2- Am i doing something wrong by assigning nil to view for unloading it? If so, how should i unload the view properly in such case like this(tabbed application)?
  • 3- Is anything wrong with the 1. solution? Does it seem like a kludge? Is that assumption about superview and viewWillAppear correct?

EDIT : It seems that when viewDidLoad is called earlier than it should(i.e when view nilled in viewWillDisappear instead of viewDidDisappear), superview is not set.

0 投票
1 回答
762 浏览

ios - 更改超级视图会破坏 UIPanGestureRecognizer

我正在尝试实现一个可以拖出其超级视图的 UIView。

我尝试将一个添加UIPanGestureRecognizer到我希望能够拖动的视图中。然而,似乎从其父视图中删除 UIView 并将其添加到另一个视图,正在破坏手势识别器。

UIGestureRecognizerStateBegan注释掉代码后,其他两个块中的代码可以正常运行,但是当我恢复它时,永远无法实现 UIGestureRecognizerStateChanged 和 UIGestureRecognizerStateEnded 状态。

出了什么问题?

0 投票
0 回答
353 浏览

objective-c - IOS - Superview 在横向模式下捕捉触摸事件

我有一个以编程方式创建的 UIViewController,当我将它的视图插入到我的一般视图中时,UIView 底部的 300 像素没有收到任何触摸事件,触摸事件被主 UIView 超级视图捕获。

重要的事实是,仅在我处于横向模式时才会发生。

有任何想法吗?

编辑:这是一个屏幕截图,橙色背景是具有自己的 UIViewController 并且需要触摸的 UIView,但正如我所说,主 UIViewController 正在捕获底部的最后一个像素(大约 275)。所以按钮永远不会被调用。仅在横向模式下!

图库截图