简体   繁体   中英

UITableViewCell does not animate properly if width is less than screen size

I have a subclass of UITableViewCell and I am wanting to provide some custom animations when events occur. I have been struggling to figure out why I kept receiving the same animation (I'm assuming UITableViewRowAnimationFade, the cell would just disappear and the one below it slid up) and I finally decided to dig into the problem. I found that when I set the size of the cell to be less than 320 (or I'm assuming exactly equal to the size of the screen you presently on) it will fall back to this default animation.

My custom cell is like a floating box (I have 1 cell per section, with many sections) and I set it up like so

self.frame = CGRectMake(5, self.frame.origin.y, 310, self.frame.size.height);
self.contentView.frame = CGRectMake(0, 0, 310, self.frame.size.height);

but I get the default animation every time. If I change it to

self.frame = CGRectMake(5, self.frame.origin.y, 320, self.frame.size.height);
self.contentView.frame = CGRectMake(0, 0, 320, self.frame.size.height);

The different animations work just fine.

Does anyone have any clue why this would be? I'm wondering if it is intended to work this way and I need to change the way my cell is setup or if there is a workaround.

Thanks.

EDIT: Screen Shot

在此处输入图片说明

You make the contentView.background color clear, so the cell itself is totally transparent. Then you add a view to the contentView that has a background color - a view with a frame that insets it on the left and right (and possibly top and bottom). [I'm doing something almost exactly the same right now - for a new feature for my app in the store]. Lets call this view the containerView (as it will contain all the other views). You might want to set the clipsContentsToBounds property so its impossible for any of your subviews to 'stick out' of it.

You can then add additional views to the container view. Since I always recycle my cells, you want to set tag values on all the container subviews so you can easily find them and set an appropriate property (image, text, color, etc).

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