0

I have a UIViewController that does a lot of data processing up front in order to render a UIScrollView. The bizarre thing is, even once all the processing/rendering is done, the UIScrollView is very laggy when scrolling.

I've double checked that nothing is being processed, and I'm not even using the scrollViewDidScroll delegate method.

I also have a UITableView in the view (currently with no data) that is also laggy, so it's affecting everything in that view. (If I change tabs, none of the other views show any lag).

Could high memory usage cause this lag? It seems strange considering I remove most of the loaded data after processing. What else could it be?

Edit: To clarify, my UITableView is empty at the moment, so it's not a recycling issue. I just mentioned the UITableView because it's not just the UIScrollView that is lagging.

Edit 2: As @MacKentoch pointed out, using rounding can cause lag. I removed the rounding from my subviews and it fixed the issue. I was using this to round the squares to circles:

label.layer.cornerRadius = height / 2
label.layer.masksToBounds = true

Is there a more efficient way to do this?

Luke Sapan
  • 3,052
  • 4
  • 28
  • 50
  • Is it laggy on all simulators? It happens to be laggy with iPhone 6 plus simulators (because of zoom out otherwise it would take all my screen) – MacKentoch Apr 20 '15 at 19:00
  • Oh it's actually not super laggy on the simulator. It's more laggy on actual devices. I've come to expect it from the 6+ simulator at this point haha. – Luke Sapan Apr 20 '15 at 19:01
  • Can you run the Time Profiler instrument and post a screenshot/code for the top 5 entries? – jszumski Apr 20 '15 at 19:13
  • 1
    Ok. **I'm not sure it is the same case**. But, I had same issue on a TableView when scrolling. In fact, I had some effect on multiple **subviews layers** (**shadows**, rounded...). I removed shadow effect then it was better. Shadow effects can cost too much to render on scrolling I suppose. Otherwise have you **checked** your **memory usage**? – MacKentoch Apr 20 '15 at 19:17
  • Without code is a bit hard, are you sure you are recycling objects in cell as well? – jalone Apr 20 '15 at 19:19
  • @MacKentoch you may be on to something. My `UIScrollView` is full of subviews that are all being rounded. (It's a calendar, and each day is a colored circle). I'll try taking off rounding and see what happens. I'll also run it through the Time Profiler. – Luke Sapan Apr 20 '15 at 19:40
  • I don't believe it. @MacKentoch you were 100% right. I removed my layer modifications and it's 100% smooth. Here's the catch though, they look horrible as colored squares. Is there a more efficient way to display them as circles? – Luke Sapan Apr 20 '15 at 19:41

2 Answers2

0

Thanks to @MacKentoch for suggesting it could be the rounded corners. After determining that was the issue, this SO answer quickly solved the problem:

UILabel layer cornerRadius negatively impacting performance

Community
  • 1
  • 1
Luke Sapan
  • 3,052
  • 4
  • 28
  • 50
0

Shadow effet impact scrolling rendering (the more subviews are shadowed the worse it is).

Concerning rounded corners it may impact too (but less I think).

The solution :

  • shadow : from an image or place a subview behind to make a shadow like effect

  • rounded corner : image

That is what I did, It was a bit a defeat not to be able to do like I wanted but result was OK.

Community
  • 1
  • 1
MacKentoch
  • 2,086
  • 3
  • 12
  • 19
  • Just a heads up for the future, you can do the rounded corners without `masksToBounds` which was the real culprit. Check out the link in my answer, you can do it without images. – Luke Sapan Apr 20 '15 at 19:56