简体   繁体   English

如何将对象转发到单独的子视图?

[英]How can i forward objects to separate subviews?

I have a UIView and a ScrollView as 2 separate subviews.我有一个 UIView 和一个 ScrollView 作为 2 个单独的子视图。 How can i drag a UIView(named "a") from my UIView and have the scrollView "take over" that dragged "a" UIView?如何从我的 UIView 中拖动 UIView(名为“a”)并让滚动视图“接管”拖动“a”UIView 的滚动视图?

It really depends on what you exactly mean by 'take over' the UIView.这实际上取决于您“接管” UIView 的确切含义。

If you simply want to change the parent view, when your view is 'dropped' then remove it as a Subview of it's parent view & add the UIView as a Subview of the UIScrollview.如果您只是想更改父视图,当您的视图被“删除”时,请将其作为父视图的子视图删除,并将 UIView 添加为 UIScrollview 的子视图。 If the original ParentView has a property that holds the UIView, then it will still retain the instance but the view will be one level down the hierarchy.如果原始 ParentView 具有包含 UIView 的属性,则它仍将保留实例,但视图将位于层次结构的下一层。

If you want to past the entire instance of the view to UIScrollView, you'll have to subclass UIScrollView & add a property for the UIView.如果要将视图的整个实例传递给 UIScrollView,则必须将 UIScrollView 子类化并为 UIView 添加一个属性。 Then you can either create a custom setter (ie don't @synthesize ) that will retain the instance & do the above view adding/removing然后您可以创建一个自定义设置器(即不要@synthesize )将保留实例并执行上述视图添加/删除

OR或者

Create a - (void)provideNewView:(UIView *)newView method that will assign to the local property and do the view adding/removing.创建一个- (void)provideNewView:(UIView *)newView方法,该方法将分配给本地属性并执行视图添加/删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM