sono riuscito ad ottenere un UIView in scala di grigi con l'aggiunta del seguente vista sulla parte superiore:UIView in scala di grigi. Visualizzazione non essere ridisegnato
@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
funziona, ma il contenuto non viene aggiornato a meno che io chiamo manualmente setNeedsDisplay. (Posso premere un UIButton e l'azione si attiva, ma nulla cambia nell'aspetto) Quindi, per comportarsi come previsto, chiamo setNeedsDisplay 60 volte al secondo. Che cosa sto facendo di sbagliato?
UPDATE:
Il viewcontroller INITs l'OverlayView con questo:
- (void)viewDidLoad
{
[super viewDidLoad];
GreyscaleAllView *grey = [[[GreyscaleAllView alloc] initWithFrame:self.view.frame] autorelease];
grey.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
grey.userInteractionEnabled = NO;
[self.view addSubview:grey];
}
Ho aggiunto questo per i panorami underlaying per ridisegnare:
@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];
}
può aggiungi il codice da dove stai inizializzando questa vista in scala di grigi? – rishi
aggiunto viewcontroller initcode e redrawcode – jalmaas
provare a utilizzare GreyscaleAllView * gray = [[[GreyscaleAllView alloc] initWithFrame: CGRectMake (0,0,320,480)] autorelease]; – rishi