其標記爲重複或重複的問題之前,請閱讀我的問題...如何以編程方式繪製邊框並在UIImageview周圍的文字後移除它?
我有一個scroleView中,我把一些圖片以表格的形式。
當用戶點擊其中一個時,會顯示下一個視圖控制器,並且點擊圖像的uiview會顯示綠色邊框。
- 而當用戶導航回到此視圖時,單擊的圖像顯示爲帶有綠色邊框的 。這一切工作正常
但是,當用戶點擊其他圖像的問題開始:前一次單擊圖像沒有恢復正常,即,其邊界在那裏停留,即使我把它的寬度爲0.0和色彩clearColor
請指導我如何消除這些邊界
我的代碼如下:
for (int row = 0; row < r; ++row)
{
for (int col = 0; col < 2; ++col)
{
int index = (row * 2) + col;
if(index < [tempArr count])
{
CGRect frame = CGRectMake(10+col*(10+145),10+row*(5+100),145, 100);
UIView *fr = [[UIView alloc] initWithFrame:frame];
CGRect imgFrame = CGRectMake(0, 0, 145, 100);
UIImageView *imgView = [[UIImageView alloc]initWithFrame:imgFrame];
imgView.image = [UIImage imageNamed:[[tempArr objectAtIndex:index]valueForKey:@"add"]];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
fr.layer.borderWidth = 0.0f;
fr.layer.borderColor = [UIColor greenColor].CGColor;
if(selctedFrame == index)//Here i put border
{
fr.layer.borderWidth = 2.0f;
fr.layer.borderColor = [UIColor greenColor].CGColor;
}
else //here i remove them
{
fr.layer.borderWidth = 0.0f;
fr.layer.borderColor = [UIColor clearColor].CGColor;
}
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[fr addGestureRecognizer:tapGesture];
[fr addSubview:imgView];
fr.tag = index;
[self.scrollDisplay addSubview:fr];
[self.scrollDisplay bringSubviewToFront:fr];
}
}
}
[self.view addSubview:self.scrollDisplay];
這種方法被稱爲在viewWillAppear:animated:
方法
編輯
後,一些導航來回
好吧我現在就試試這個 – 2012-04-11 05:12:54
nop沒有改變只是看到我的應用程序屏幕截圖我剛剛添加 – 2012-04-11 05:22:15
實際上viewWillAppear:這個滾動視圖是用圖像創建的,當圖像是全尺寸的時候,即左上角的那個,邊框將被重置,但是較小尺寸的圖像保留邊框,所以我必須每次都將圖像視圖添加到滾動視圖沒有東西顯示在滾動視圖 – 2012-04-16 07:30:01