me las arreglé para conseguir un UIView en escala de grises, añadiendo la siguiente vista en la parte superior:UIView en escala de grises. Ver no ser redibujado
@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
funciona, pero el contenido no se actualiza a menos que yo llamo manualmente setNeedsDisplay. (Puedo presionar un botón UIButton y la acción se dispara, pero nada cambia en apariencia). Para que se comporte como se esperaba, invoco setNeedsDisplay 60 veces por segundo. ¿Qué estoy haciendo mal?
ACTUALIZACIÓN:
El viewcontroller ensu la OverlayView con esto:
- (void)viewDidLoad
{
[super viewDidLoad];
GreyscaleAllView *grey = [[[GreyscaleAllView alloc] initWithFrame:self.view.frame] autorelease];
grey.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
grey.userInteractionEnabled = NO;
[self.view addSubview:grey];
}
He añadido esto a la opinión subyacente para volver a dibujar:
@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];
}
puede Agrega el código desde donde está inicializando esta vista de escala de grises? – rishi
addcontroller initcode y redrawcode – jalmaas
intente utilizar GreyscaleAllView * gray = [[[GreyscaleAllView alloc] initWithFrame: CGRectMake (0,0,320,480)] liberación automática]; – rishi