UPDATE:
這是絕對荒謬的,我不得不這樣做,因爲必須有一個更簡單的方法,但是我最終定位兩個獨立UIViews了另一種,然後相應地設置不透明度和透明度。這工作。
我想現在就寫一個新的觀點,即這是否它看起來像正確的方式:
UIView : myview
- (subview) UIImageView
- (subview) UIImageView
The code looks something like this...
@interface customView : UIView
{
...
UIImageView *foregroundImage;
UIImageView *backgroundImage;
...
}
@end
@implementation
- (void) awakeFromNib
{
...
self.backgroundColor = [UIColor whiteColor];
self.alpha = 1;
self.opaque = YES;
self.clearsContextBeforeDrawing = FALSE;
[backgroundImage initWithImage:<...>];
backgroundImage.alpha = 0.5; // Yes, this should be 0.5. The background should be a bit lucid
backgroundImage.opaque = YES; // I want the white background of the parent UIView to show through
[foregroundImage initWithImage:<...>];
foregroundImage.alpha = 1; // Yes, this should be 1. The surrounding space is clear...
backgroundImage.opaque = YES;
[self addSubview:backgroundImage];
[self addSubview:foregroundImage];
[self bringSubviewToFront:foregroundImage];
[self setNeedsLayout];
[foregroundImage setNeedsDisplay];
[backgroundImage setNeedsDisplay];
[self setNeedsDisplay];
...
}
- (void) drawRect: (CGRect) rect
{
...
// update the images to latest
[backgroundImage setImage:<..new..>];
[foregroundImage setImage:<..new..>];
[backgroundImage setNeedsDisplay]; // necessary?
[foregroundImage setNeedsDisplay]; // necessary?
[self setNeedsDisplay]; // necessary?
...
}
@end
結果?沒有。沒有更新。我讀過其他人也遇到過這個問題(設置Image屬性時UIImageView沒有更新),但還沒有看到解決方案。這些圖像是由在觸摸事件被寫入到屏幕外的緩衝區等來
我知道,這些緩衝器具有正確的圖像,因爲如果我這樣做:
CGImageRef bitmap = CGBitmapContextCreateImage(bufferContext);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0,0,self.bounds.size.width, ...height), bitmap);
CGImageRelease(bitmap);
...我可以看到正確的圖像。 UIImageViews似乎不想更新。它們的不透明度等也相應設定。
會繼續磨,不想爲此寫個黑客。應該有一個簡單,優雅的方式...
任何幫助/指導表示讚賞。