In my iPad app I have a UIScrollView that contains a bunch of UISwitch elements. A group of them (about 12) can be enabled/disabled depending on the group state.
When the group state is "enabled" and I set the UISwitch enabled property to YES the entire scrollview scrolls naturally. When I set the UISwitch enabled property to NO the UIScrollView lags and stutters when scrolling.
I enable/disable the twelve UISwitches like this:
[self.switchOneOutlet setEnabled:NO];
and
[self.switchOneOutlet setEnabled:YES];
(Of course switchOneOutlet is named more descriptively for each switch.)
Note: I am using Auto Layout but I've tested to see if it has any effect and it doesn't. This seems to be tied strictly to the enabled state of the UISwitch elements sitting in the UIScrollView. I don't believe this is an Auto Layout issue.
Any ideas what could be causing this stutter when the UISwitches are disabled?
The problem is that when the switches are disabled, they have an alpha applied to them to grey them out. This causes them and their subviews to be rendered off-screen each frame. (You can see this if you use the Core Animation instrument and check "Color offscreen-rendered yellow"; compare enabled to disabled.) This off-screen rendering (each frame) is expensive, and why you're having performance problems.
The easiest solution is to ask Core Animation to cache the switch's appearance between frames. (Since their appearance doesn't change while scrolling, this improves performance dramatically.) You can do this with:
mySwitch.layer.shouldRasterize = YES;
mySwitch.layer.rasterizationScale = [[UIScreen mainScreen] scale];
Note that this caching only speeds things up if the switches themselves do not change in appearance. You may want to set shouldRasterize to NO before allowing the user to interact with those switches. (So, perhaps turn it on when they start scrolling, disable it when they stop? You might just have to play around with this to get the right trade off for your case.)