在我正在構建的應用程序中,導入了方形圖像,它被分成16個圖塊,並且從頂部開始將這些圖塊放置在屏幕上的正方形中。但是,我在瓦片頂部的頂部添加了一個額外的信息欄,因此我需要將這組瓦片進一步向下移動到屏幕上。我已經玩過代碼所做的for循環和座標,但沒有給我所期望的尊重。定位多個UIImage - 目標C
-(void) initPuzzle:(NSString *) imagePath{
UIImage *orgImage = [UIImage imageNamed:imagePath];
if(orgImage == nil){
return;
}
[self.tiles removeAllObjects];
tileWidth = orgImage.size.width/NUM_HORIZONTAL_PIECES;
tileHeight = orgImage.size.height/NUM_VERTICAL_PIECES;
blankPosition = CGPointMake(NUM_HORIZONTAL_PIECES-1, NUM_VERTICAL_PIECES-1);
for(int x=0; x<NUM_HORIZONTAL_PIECES; x++){
for(int y=0; y<NUM_VERTICAL_PIECES; y++){
// *** The coordinates need to be altered - ?
CGPoint orgPosition = CGPointMake(x,y);
if(blankPosition.x == orgPosition.x && blankPosition.y == orgPosition.y){
continue;
}
CGRect frame = CGRectMake(tileWidth*x, tileHeight*y,
tileWidth, tileHeight);
CGImageRef tileImageRef = CGImageCreateWithImageInRect(orgImage.CGImage, frame);
UIImage *tileImage = [UIImage imageWithCGImage:tileImageRef];
CGRect tileFrame = CGRectMake((tileWidth+TILE_SPACING)*x, (tileHeight+TILE_SPACING)*y,
tileWidth, tileHeight);
tileImageView = [[Tile alloc] initWithImage:tileImage];
tileImageView.frame = tileFrame;
tileImageView.originalPosition = orgPosition;
tileImageView.currentPosition = orgPosition;
CGImageRelease(tileImageRef);
[tiles addObject:tileImageView];
// now add to view
[self.view insertSubview:tileImageView atIndex:0];
}
}
[self shuffle];
}
你的問題是什麼?我看到了信息,但並不是說你在問什麼。 – WendiKidd 2012-07-07 00:16:25
我怎樣才能將這組拼貼放置在屏幕的下方,比如100像素左右。 – Alex 2012-07-07 00:17:18