我有3 * 3的圖像從一個圖像(通過裁剪),但如何管理這些imageView的移動,我必須聲明所有這些或任何其他方式的不同對象是他們......有可能使用數組管理這些太多的圖像....請幫助好友玩UIImageView?
我們可以通過對象數組來完成...?
- (void)viewDidLoad {
UIImage *img = [UIImage imageNamed:@"3.jpg"];
for(int i = 0;i < 3;i++)
{
for (int j = 0; j < 3 ; j++)
[self SetImagePeces:i :j];
}
[super viewDidLoad];
}
-(void) SetImagePeces:(int)col:(int)row
{
UIImage *img = [UIImage imageNamed:@"3.jpg"];
img1 = [[UIImageView alloc] init];
img1.frame = CGRectMake(0 + 235 * col, 0 + 235 * row, 233, 233);
img1.tag = row;
img1.userInteractionEnabled = YES;
CGRect clippedRect = CGRectMake(0 + 233 * col,700 - 233 * row, 233, 233);
UIImage *imgV = [self imageByCropping:img toRect:clippedRect];
img1.image = imgV;
[self.view addSubview:img1];
[img1 release];
}
更新::
不過現在我嘗試在700 * 700大小的圖片,但如何將圖像的大小我們任何規模大小約束..
**觸摸事件:: **
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if (touch.view == img2) {
if (c2 == 0) {
tempImg = img2.image;
[flag replaceObjectAtIndex:1 withObject:@"1"];
c2++;
}
else {
for(int j=0;j<9;j++)
{
if(j==1)
{[flag replaceObjectAtIndex:j withObject:@"0"];}
else
{
int a=[[flag objectAtIndex:j]integerValue];
if (a==1) {
img3.image=img2.image;
[flag replaceObjectAtIndex:j withObject:@"0"];
}
}
}
img2.image = tempImg;
c2 = 0;
}
}
if (touch.view == img3) {
if (c2 == 0) {
tempImg = img3.image;
[flag replaceObjectAtIndex:2 withObject:@"1"];
c2++;
}
else {
for(int j=0;j<9;j++)
{
if(j==2)
{[flag replaceObjectAtIndex:j withObject:@"0"];}
else
{
int a=[[flag objectAtIndex:j]integerValue];
if (a==1) {
img2.image=img3.image;
[flag replaceObjectAtIndex:j withObject:@"0"];
}
}
}
img3.image = tempImg;
c2 = 0;
}
}
}
這裏我換觸摸圖像開始方法,以便僅實現2幅圖像,但實在是太困難的奶源更多圖片
Thanx預先
我上面添加了我的代碼pls ...給我建議...我必須隨機設置圖像比觸摸重新排列它... – AJPatel 2011-04-27 13:44:49
謝謝你哥們我試試這個,直到現在我使用單獨的UIImageview對象和使用觸摸事件。讓我們看看可能對我有用...... – AJPatel 2011-04-28 08:39:51
不客氣。 :) – AechoLiu 2011-05-30 14:06:12