如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)


問題描述

如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)

I have a UIView and a ScrollView as 2 separate subviews. How can i drag a UIView(named "a") from my UIView and have the scrollView "take over" that dragged "a" UIView?

‑‑‑‑‑

參考解法

方法 1:

It really depends on what you exactly mean by 'take over' the 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. 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.

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. Then you can either create a custom setter (i.e. don't @synthesize) that will retain the instance & do the above view adding/removing 

OR 

Create a ‑ (void)provideNewView:(UIView *)newView method that will assign to the local property and do the view adding/removing.

(by AlexCraig Stanford)

參考文件

  1. How can i forward objects to separate subviews? (CC BY‑SA 3.0/4.0)

#cocoa-touch #objective-c #iphone #iOS






相關問題

防止 UITableView 在自定義子視圖處理觸摸時滾動 (Prevent UITableView from scrolling when custom subview is handling touches)

NSMutableArray removeObjectAtIndex 在第二次執行時崩潰 (NSMutableArray removeObjectAtIndex crashes on second execution)

Apakah NSURLConnections termasuk dalam model atau pengontrol saya? (Do NSURLConnections belong in my model or controller?)

Lợi ích của việc sử dụng NSString tĩnh cho CellIdentifier là gì? (Whats the advantage of using a static NSString for CellIdentifier?)

CGContextRef 中的坐標係是什麼樣的? (How does the coordinate system in an CGContextRef look like?)

無法在不崩潰的情況下設置 ABPeoplePickerNavigationController 的 addressBook 屬性 (Can't set the addressBook property of ABPeoplePickerNavigationController without crashing)

tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub-views)

界面生成器添加了一個標籤欄按鈕,但未顯示 (Interface builder added one tab bar button, but not showing up)

iVar getter / 方法同名? (iVar getter / method with same name?)

如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)

捕捉返回按鈕導航事件 (Catching back button navigation event)

如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)







留言討論