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