开发者

iphone, ipad Duplicate UIView - Cloned View

How to Duplicate a UIView. requirement is there should be two views inside a view for ex consider View A and View B. changing one view also should change another view.

for example consider 开发者_如何学运维am added a mpmediaplayer in view A means view B should show same video which is there in view A and if i moving anything in view A means ie forwarding video, volume control etc.. the scond view shold display the same thing.


There is no easy way to clone a view and then to update two views by one line of code. Because their underlying CALayers are different. But for duplicating a UIView, here is a new method you can use: Use UIView's method:

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates

This is the fastest way to draw a view. Available in iOS 7.


UIViews are not easily duplicated except by hand - i.e. creating the view manually in the loadView and instantiating two copies. Linking the behavior would be up to you. Some may suggest serializing the UIView and then deserializing a copy, but it's unlikely that the subviews will implement NSCoder (the media player and UIImages certainly don't), making this usually a non-starter.


This is actually very easily done. Each View should be controlled by one controller. Then when actions are done on one view the controller will simply update the data model and the other view will get updated automatically. This is in fact the power of the the model view control design. Now it should be understood that this means both views will in fact be sharing data. Their local states will be separate, but those states will be kept in sync with the data model by the controller. The data model will be unified and therefore the views should stay synced up.

for more on the MVC (model view control) see this article http://developer.apple.com/library/ios/#documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜