画像を拡大してから通常のサイズに縮小できるコードがありますが、画像を何度もタップすると、その画像またはその前に表示されていた画像の大きなバージョンが作成され、それを行うことができませんサイズ変更されます。よくわかりませんが、これら両方のコードの 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)];
また、画像が最初に反応するのに2回のタッチが必要で、その後はすべてのタッチが機能する理由と、画像のすぐ近くでタッチできるのに、実際の画像に触れていると感じるのはなぜですか? 非常に多くの質問。