-1
我有一些代码,允许我放大,然后缩小到正常大小的图片,但如果我点击图片太多次,它会创建该图片的大版本或图片在它之前查看并且无法调整大小。我不确定,但我认为这两段代码的addSubview语句之间可能会有矛盾之处。这是ImageEnlarge
的实施。相互矛盾的代码导致多个图像
@implementation ImageEnlarge
-(UIImageView *)internal{
return internal;
}
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
internal = [[UIImageView alloc] initWithFrame:self.bounds];
[internal setBackgroundColor:[UIColor blackColor]];
[internal setContentMode:UIViewContentModeScaleToFill];
[self addSubview:(internal)];
}
return self;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)touch {
if (isLarge) [self makeSmall];
else [self makeFull];
}
-(void) makeFull {
[[self superview] bringSubviewToFront:self];
isLarge = YES;
CGSize largePicSize = CGSizeMake(156, 156);
CGPoint largePicOrigin = CGPointMake(110, 96);
CGRect largeFrame;
largeFrame.size = largePicSize;
largeFrame.origin = largePicOrigin;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[internal setFrame:self.bounds];
[self setFrame:largeFrame];
[UIView commitAnimations];
}
-(void) makeSmall {
isLarge = NO;
CGSize normPicSize = CGSizeMake(100, 100);
CGPoint normPicOrigin = CGPointMake(82, 74);
CGRect original;
original.size = normPicSize;
original.origin = normPicOrigin;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[internal setFrame:self.bounds];
[self setFrame:original];
[UIView commitAnimations];
}
@end
这是在我的图像上执行此操作。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *albumArtImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.churchwebserver.org/imagename.jpg"]];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *albumArt = [UIImage imageWithData:albumArtImageData];
CGSize picSize = CGSizeMake(100, 100);
CGPoint picOrigin = CGPointMake(110, 96);
CGRect picFrame;
picFrame.size = picSize;
picFrame.origin = picOrigin;
ImageEnlarge * imEn =[[ImageEnlarge alloc]initWithFrame:picFrame];
[[imEn internal]setImage:albumArt];
[self.view addSubview:(imEn)];
问题也仍然为什么需要两个触摸的图像最初响应之后,它的作品每一个接触,为什么我可以在靠近触摸到的图像,它仍然感觉到我接触实际图像?这么多的问题。
它有一个黑色的背景不是黑色的边框。 – 2013-02-15 15:34:30
我在谈论UIImageview里面的图像 – Luke 2013-02-15 15:55:56
@CarlVeazey当你有机会的时候... – 2013-02-15 20:48:16