पता नहीं कि आपका असली इरादा क्या है, लेकिन यह दो बार दृश्य आकर्षित करेगा, उपयोगकर्ता इंटरैक्शन आदि दूसरे दृश्य पर काम नहीं करेगा। यह समाधान विभिन्न फ्रेम आकारों का ख्याल नहीं रखता है। देखें की
हैडर क्या आप
#import "SrcView.h"
#import "CloneView.h"
@implementation SrcView
@synthesize cloneView;
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
[cloneView setNeedsDisplay];
}
- (UIView *)cloneView {
if (!cloneView) {
cloneView = [[CloneView alloc] initWithView:self];
}
return cloneView;
}
@end
@implementation CloneView
@synthesize srcView;
- (id)initWithView:(UIView *)src {
self = [super initWithFrame:src.frame];
if (self) {
srcView = src;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[srcView.layer renderInContext:UIGraphicsGetCurrentContext()];
}
@end
क्लोन अब तुम सिर्फ cloneView कॉल कर सकते हैं और इसे कहीं आप चाहते हैं जोड़ना चाहते हैं दृश्य की
@interface SrcView : UIView
@property(nonatomic, readonly, strong) UIView *cloneView;
@end
@interface CloneView : UIView
@property(nonatomic, weak) UIView *srcView;
- (id)initWithView:(UIView *)src;
@end
कार्यान्वयन क्लोन करने के लिए चाहते हैं।
स्रोत
2012-04-28 19:54:03
एक नया उदाहरण बनाने के अलावा खुद को किसी अन्य तरीके से प्रस्तुत करें? यह सब के बाद, एक वस्तु है। – jmstone617