2014-11-06 47 views
0

我有一個UIScrollView子視圖。它包含產品/項目的結果列表。與UIImageViewUILabel。它可能包含很多項目。我的問題是,當我按下按鈕(網格按鈕)將UI結果更改爲網格視圖時,它在完成處理之前需要時間。有沒有辦法讓這個更快?像刪除在屏幕/ UIScrollView中不可見的圖像?有很多子視圖的UIScrollView需要時間來處理

這裏是我的ListView控件

代碼
-(void)actionList { 

NSLog(@"List!!"); 
isGrid = NO; 
for(UIView*iView in sv_results.subviews){ 
    for(UILabel *iView2 in iView.subviews){ 
     if([iView2 isMemberOfClass:[UILabel class]]){ 
      if(iView2.tag == 0) 
      { 
       iView2.frame = CGRectMake(80, 0, 150, 50); 
       iView2.font = [UIFont boldSystemFontOfSize:12.0f]; 
      } 
      else if(iView2.tag == 1) 
      { 
       pricewidth = [iView2.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.0f]}]; 
       iView2.frame = CGRectMake(80, 20, pricewidth.width+1, 50); 
       iView2.font = [UIFont systemFontOfSize:13.0f]; 
       for(UIView *discountline in iView2.subviews) 
       { 
        discountline.frame = CGRectMake(0, iView2.frame.size.height/2, iView2.frame.size.width, 1); 
       } 
      } 
      else if(iView2.tag == 2) 
      { 
       iView2.frame = CGRectMake(screenRect.size.width-60, 30, 50, 15); 
       iView2.font = [UIFont systemFontOfSize:10.0f]; 
      } 
      else if(iView2.tag == 3) 
      { 
       iView2.frame = CGRectMake(140, 20, 150, 50); 
       iView2.font = [UIFont systemFontOfSize:13.0f]; 
      } 
      else { 
       iView2.frame = CGRectMake(80, 0, 150, 50); 
       iView2.font = [UIFont boldSystemFontOfSize:12.0f]; 
      } 
     } 
     if([iView2 isMemberOfClass:[AsyncImageView class]]){ 
      iView2.frame = CGRectMake(15,12,50,50); 
      iView2.layer.cornerRadius = 5; 
     } 
    } 


    for(int i = 0;i<=allAvailableData;i++) 
    { 
     if(iView.tag == i) 
     { 
      iView.frame = CGRectMake(0,((i-1)*75),320,75); 
     } 
     //sv_results.contentSize = CGSizeMake(320,yPosition);//optional resize height scrollview from gridview 
    } 


    iView.layer.borderWidth = .3f; 
} 
sv_results.contentSize = CGSizeMake(320,(allAvailableData)*75); 
} 
+1

你基本上是問一個UITableView是否存在,答案是肯定的。當UITableViewCell當前不在屏幕上可見時,UI元素不會加載到內存中。它重新使用現有的單元格。 – 2014-11-06 06:45:36

+0

我正在使用'UIScrollView'。我正在考慮將它更改爲List的「UITableView」和Grid的'UICollectionView'。你怎麼看? – 2014-11-06 06:48:27

+0

我會建議做這個開關。 UiTableView和UICollectionView是爲此目的而設計的。 UIScrollView實際上並不是要處理任意數量的動態呈現。起初它會稍微複雜一點,但你會發現UITableView/UICollectionView爲你做了很多工作。 – 2014-11-06 06:52:49

回答

0

只需使用

scrollView.delaysContentTouches = NO; 

決定滾動視圖是否延遲觸摸下手勢的處理布爾值。
如果此屬性的值爲YES,那麼滾動視圖會延遲處理觸摸手勢,直到它可以確定滾動是否爲意圖。如果值爲NO,滾動視圖會立即調用touchesShouldBegin:withEvent:inContentView :.默認值是YES。

這意味着,默認情況下,scrollView會延遲觸摸,您可以通過上面的代碼禁用該功能,
希望它能解決您的問題。

0

我想你應該實現的UITableView,所以它不會花時間,你可以加載「dispatch_async」的形象。我希望你能以這種方式獲得解決方案。

相關問題