2015-11-21 2 views
0

В моем cellForRowAtIndexPath методе я поставил cornerRadius в layer на моем изображении:Почему изменение этого CALayer в UITableViewCell вызывает неприятный графический сбой?

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("feedCell")! 

    if self.pictunes?.count > 0 { 
     // There are some pictunes to show; Create and update the posts 
     if self.pictuneImages.count > indexPath.row { 

      // We have an image for the user who made the current pictune 
      if let pictunerImageView = cell.contentView.viewWithTag(2) as? UIImageView { 
       pictunerImageView.layer.cornerRadius = 17.5 // Cut it to a circle 
       pictunerImageView.image = self.pictunerImages[0] 
      } 

      // We also have an image for the pictune at the current post 
      if let pictuneImageView = cell.contentView.viewWithTag(1) as? UIImageView { 
       pictuneImageView.image = self.pictuneImages[indexPath.row] 

      } 
     } 
     return cell 
    } else { 
     // No pictunes have loaded yet; We probably need more time 
     // to load the image and audio assets for some of them 
     cell.textLabel!.text = "No Pictunes Available Yet" 
     return cell 
    } 
} 

Но когда я прокручиваю я вижу этот неприятный фон эффект:

enter image description here

Как мне избавиться от этот эффект? Очистка фонового контекста не помогла. Благодаря!

+0

Гиф слишком мал, чтобы действительно видеть, о чем вы говорите, но я предполагаю, что вам нужно сказать pictunerImageView.layer.masksToBounds = true после того, как вы установите cornerRadius – beyowulf

+0

, о котором он говорит, является тот факт, что при прокрутке нижние два угла изображения профиля округлены - если он достигает вершины, это изменяется, а верхние два угла округляются. – luk2302

+0

^Точно. Извините, что GIF настолько мал. Существует ограничение в 2 МБ. Я попробую добавить 'masksToBounds' к' true', как вы предложили, beyowulf. – IIllIIll

ответ

1

Set:

pictunerImageView.layer.masksToBounds = true 

после:

pictunerImageView.layer.cornerRadius = 17.5 

Вы также могли бы изменить это:

pictunerImageView.layer.cornerRadius = pictunerImageView.frame.size.height *0.5 

В случае, если вы когда-либо хотите изменить размер, но все еще хотите его быть кругом.

Смежные вопросы