мне удалось получить 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. (Я могу нажать UIButton, и действие срабатывает, но ничего не меняется по внешнему виду). Поэтому, чтобы он вел себя так, как ожидалось, я вызываю setNeedsDisplay 60 раз в секунду. Что я делаю не так?
UPDATE:
ViewController inits в OverlayView с этим:
- (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
добавлен viewcoderler initcode и redrawcode – jalmaas
попробуйте использовать GreyscaleAllView * gray = [[[GreyscaleAllView alloc] initWithFrame: CGRectMake (0,0,320,480)] autorelease]; – rishi