简体   繁体   中英

CALayer animation jumpy in UITableViewCell on iPhone 3gs 4.2.1

I've created a custom view that resizes CALayers in when a pan gesture is triggered. When the control is added to a normal UIVIew , the animation behaves exactly as expected.

When the view is added to a UITableViewCell via addSubView the animation is jumpy. I placed some NSLog statements in the gesture handler, and it's behaving exactly as expected.

Is there anything about UITableView or UITableViewCell that would cause this unexpected behavior I am experiencing? Is it even correct to add custom view by using addSubView?

EDIT

I have a little more information on the problem. The issue only seems to be appearing on certain environments.

*iPhone 3GS, iOS 4.2.1 - YES
iPod Touch (Retnia), 5.1 - NO
iPod Simulator 4.2 - NO
iPod Simulator 5.1 - NO

I've also put into place the suggestions from Lorean and DavidH, which didn't solve the issue.

*When I build from XCode, there is a message next to the 3gs device that says "Overriding base SDK to 4.3"

Could this be a potential problem?

While I agree the view should be placed as a subview in the contentView, there is another potential issue. Animations inside moving scrollViews are historically terrible, as the overall system is not designed to support two uncoupled animations.

The solution for that issue is when a user touches the cell, you disable scrolling (ie myTableView.scrollEnabled = NO, then when the pan gesture completes (all animations), enable it again.

EDIT: This is going to sound a bit funky, but should work as I've done similar in the past. When you get the first touch event, calculate what the frame of the layer is self.view coordinates, and then add it to the view using this frame, but saving the old frame. User sees nothing and now your view is on tip. Obviously you must also prevent the table from moving. When you are done with user interactions, then move the view back to the cell using its old frame.

Depending on how you are doing touches, you may need to intercept the first touch in a clear UIView that overlays the desired panning view, and when it gets touched, do all the above, then forward the initial touch to the view. Hopefully this step is not needed.

I've implemented a hack which solves the problem. I may decide to turn off the animation altogether as it's not really needed, but if anyone has a better answer than this I will gladly accept.

if ([[[UIDevice currentDevice] systemVersion] floatValue]<5.0) 
{    
    [CATransaction begin];
    [CATransaction setDisableActions: YES];
}

//do stuff

if ([[[UIDevice currentDevice] systemVersion] floatValue]<5.0) [CATransaction commit];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM