0
我做我自己的UIImageView,像這樣:爲什麼我無法更新我的UIImageView?
@interface MyImageView : UIImageView{
}
和我有initWithFrame這樣的:
- (id)initWithFrame{
if((self = [ super initWithFrame: CGRectMake(0, 0, 175, 175) ])) {
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]];
CGRect cropRect = CGRectMake(175, 0, 175, 175);
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect);
//self = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 175, 175)];
//self.image = [UIImage imageWithCGImage:imageRef];
[self setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
}
return self;
}
我想改變,當用戶touchesBegin的形象,所以我有這樣的事情:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage2" ofType:@"png"]];
CGRect cropRect = CGRectMake(0, 0, 175, 175);
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect);
//self = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 175, 175)];
[self setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
}
我發現我無法更改圖像。所以,我添加了一行[self addSubview:imageView];在touchesBegan方法中,這是工作。但我不知道爲什麼我無法改變touchesBegan的形象,thz。
好的,我做到了,但它仍然無法正常工作。 – Tattat 2010-05-03 16:24:37