スクロール ビューの画像を読み込むために GCD を使用していますが、作成したフレームをたどるのではなく、画像がちらつく単一のフレームのみを作成します。これが私のコードです:
//Create the array
-(void)awakeFromNib {
images = [NSMutableArray arrayWithObjects: [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"imageOne" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"imageTwo" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"imageThree" ofType:@"png"]],nil];
}
//Populate scrollview
-(void)populate {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
scrollview.pagingEnabled = YES;
scrollview.backgroundColor = [UIColor clearColor];
scrollview.clipsToBounds = YES;
scrollview.delegate = self;
[scrollview setContentSize:CGSizeMake(2 * scrollview.frame.size.width, scrollview.frame.size.height)];
int number = [images count] ;
NSLog(@"%i",images);
int rowTwoInt = 0;
int rowThreeInt = 0;
int rowFourInt = 0;
for (int i = 0; i < number; i++) {
if (i <= 3) {
finalFrame = CGRectMake( i*(80), 12, 80, 80);
}
if (i == 4) {
finalFrame = CGRectMake(0, 95, 80, 80);
}
if ((i >4) && (i <= 7)) {
rowTwoInt = rowTwoInt + 80;
finalFrame = CGRectMake(rowTwoInt, 95, 80, 80);
}
if (i == 8) {
finalFrame = CGRectMake(0, 178, 80, 80);
}
if ((i > 8) && (i <= 11)) {
rowThreeInt = rowThreeInt + 80;
finalFrame = CGRectMake(rowThreeInt, 178, 80, 80);
}
if (i == 12) {
finalFrame = CGRectMake(0, 261, 80, 80);
}
if ((i > 12) && (i <= 15)) {
rowFourInt = rowFourInt + 80;
finalFrame = CGRectMake(rowFourInt, 261, 80, 80);
}
IconButton = [UIButton buttonWithType:UIButtonTypeCustom];
IconButton.frame = CGRectMake(0, 0, 57, 57);
IconButton.center = CGPointMake(40, 29);
[IconButton addTarget:self action:@selector(Selected:) forControlEvents:UIControlEventTouchUpInside];
IconButton.tag = i;
dispatch_async(queue, ^{
UIImage *icon = [images objectAtIndex:i];
dispatch_sync(dispatch_get_main_queue(), ^{
[IconButton setImage:icon forState:UIControlStateNormal];
});
});
[cell addSubview:IconButton];
cell = [[UIView alloc] initWithFrame:finalFrame];
[scrollview addSubview:cell];
それで、私は何を間違っていますか?私はGCDを初めて使用するので、おそらくそれが原因です。また、UIScrollView のパフォーマンスを改善する方法を見つけた場合は、お知らせください。