UIScrollViewにimageviewsのセットを追加しようとしています。私の問題は、x値を増やしてもイメージビューが互いに重なっていることです。奇妙なのは、この問題はios 4.2.1を搭載したデバイスのみであり、シミュレータ4.2および他のデバイスのiosで動作することです。ここから呼び出されUIImageViewがorigin.xの位置に従わない
- (void)addScrollView {
[self setImages];
scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
scrollView.delegate = self;
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
[self addSubview:scrollView];
NSUInteger nimages;
CGFloat cx = 0;
for (nimages = 1; nimages < [imagesArray count] ; nimages++) {
UIImage *image = [UIImage imageNamed:[imagesArray objectAtIndex:nimages]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.origin.x = cx;
rect.origin.y = 0;
rect.size.width = 320;
rect.size.height = 480;
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
cx += rect.size.width;
}
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
:
は、ここに私のコードです
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self addScrollView];
UIImage *handImg;
UIImageView *longhand = [[UIImageView alloc] init];
minuteHand = [[UIView alloc] initWithFrame:CGRectMake(0, 55, 320, 480)];
handImg = [UIImage imageNamed:@"clock_long_hand.png"];
longhand.image = handImg;
/************** TRY COMMENT OUT HERE **************/
longhand.frame = CGRectMake(155 - (handImg.size.width/2), 240 - handImg.size.height, handImg.size.width, handImg.size.height);
[minuteHand addSubview:longhand];
[self addSubview:minuteHand];
/************** END COMMENT OUT HERE **************/
[longhand release];
}
return self;
}
UPDATE:
このコードは、私が[自己を使用する理由であるのUIViewサブクラスであります... ]の代わりに[self.view ...]を使用します。
私は実験を試みて、指示された部分をコメントアウトすると、スクロールビューがうまく動作することがわかりました。しかし、それが含まれている場合、これはイメージビューが重なっているときです。
私はスクロールビューのコンテンツサイズが正しいことを知っています。そのインジケータはスクロールし続けていて、普通の黒い背景だけです。
私は本当になぜこれがいくつかのアイオスで動作し、他のものではないと混乱しています。あなたが手伝ってくれることを願います。
これが問題の原因かどうかはわかりませんが、scrollViewと呼ばれるバッキングiVarを使用して、scrollViewというビューコントローラのプロパティを持っているように見えます(self.scrollViewを使用しているためです)。 scrollViewを初期化するときは、保持されていないことを意味するプロパティではなく、バッキングiVarを使用します。 scrollViewを持っているところでself.scrollViewを使用しようとするとどうなりますか? – Darren
gelleryを作ろうとしていると聞こえますが、なぜ[既存のギャラリー](https://github.com/enormego/PhotoViewer)を使わないのですか? –
@Darren私はself.scrollViewを使ってみましたが、何でも私の画像はまだ重なっています。 – Jebadiah