我正在为iPad开发一个图像拼图应用程序。我成功地将图像分割成不同的图像 部件,当我在瓷砖视图中加入所有图像时,我得到iPhone尺寸的框架,对于高清图像,整个屏幕将被框架占用。所以我希望iPad中的所有图像都有一个固定大小的框架。我正在使用以下代码来分割图像并将它们放回到平铺视图中。
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++ )
{
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];
[tileImageView setUserInteractionEnabled:NO];
// now add to view
//[self.view insertSubview:tileImageView atIndex:0];
[self.view addSubview:tileImageView];
}
}
[self shuffle];
}