मैं शीर्ष पर निम्न दृश्य जोड़कर ग्रेस्केल में एक UIView पाने में कामयाब रहे:UIView। दोबारा बनाई नहीं किया जा रहा देखें
@interface GreyscaleAllView : UIView
@property (nonatomic, retain) UIView *underlyingView;
@end
@implementation GreyscaleAllView
@synthesize underlyingView;
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
// draw the image
[self.underlyingView.layer renderInContext:context];
// set the blend mode and draw rectangle on top of image
CGContextSetBlendMode(context, kCGBlendModeColor);
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, rect);
[super drawRect:rect];
}
@end
यह काम करता है, लेकिन सामग्री अद्यतन नहीं करता जब तक मैं स्वयं setNeedsDisplay कहते हैं। (मैं एक यूआईबटन और एक्शन फायर दबा सकता हूं, लेकिन उपस्थिति में कुछ भी नहीं बदलता है) तो इसके लिए उम्मीद की तरह व्यवहार करने के लिए मैं सेट सेकंड्स को प्रत्येक सेकेंड में 60 बार प्रदर्शित करता हूं। मैं क्या गलत कर रहा हूं?
अद्यतन:
ViewController इस के साथ overlayview inits:
- (void)viewDidLoad
{
[super viewDidLoad];
GreyscaleAllView *grey = [[[GreyscaleAllView alloc] initWithFrame:self.view.frame] autorelease];
grey.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
grey.userInteractionEnabled = NO;
[self.view addSubview:grey];
}
मैं पुनः बनाने का अंतर्निहित विचारों के लिए इस जोड़ दिया है:
@implementation GreyscaleAllView
- (void)setup {
self.userInteractionEnabled = FALSE;
self.contentMode = UIViewContentModeRedraw;
[self redrawAfter:1.0/60.0 repeat:YES];
}
- (void)redrawAfter:(NSTimeInterval)time repeat:(BOOL)repeat {
if(repeat) {
// NOTE: retains self - should use a proxy when finished
[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
}
[self setNeedsDisplay];
}
करना चाहिए कर सकते हैं आप उस ग्रे स्केल व्यू को शुरू करने वाले कोड से कोड जोड़ते हैं? – rishi
जोड़ा गया नियंत्रक इनिटकोड और रेड्रोकोड – jalmaas
GreyscaleAllView * ग्रे = [[[GreyscaleAllView alloc] initWithFrame का उपयोग करने का प्रयास करें: CGRectMake (0,0,320,480)] autorelease]; – rishi