当删除按钮出现时调整 UITableViewCell 内容的大小
有什么方法可以使用自动调整大小蒙版来移动我的内容,以便删除按钮不会覆盖它?谷歌搜索告诉我,我需要在子视图上设置 UIViewAutoresizingFlexibleRightMargin
的自动调整大小掩码。在我看来,UIViewAutoresizingFlexibleWidth
实际上更有意义;虽然我已经尝试过它们,但都不起作用。
我试图缩小的视图只是一个标签,它是单元格 contentView 的子视图。我不确定当删除按钮出现时 contentView 本身是否会自动调整大小;但似乎并非如此;否则我的自动调整大小蒙版应该可以工作。
如果删除按钮的存在不会导致任何视图大小调整;无论如何,我可以手动执行此操作吗?
Is there any way to use autoresizing masks to move my content so that the delete button doesn't cover it up? Googling has told me that I need to set an autoresizing mask of UIViewAutoresizingFlexibleRightMargin
on my subview. It seems to me like UIViewAutoresizingFlexibleWidth
would actually make more sense; though I've tried them both and neither works.
The view that I am trying to shrink is just a label that is a subview of the cell's contentView. I am unsure if the contentView itself automatically resizes when the delete button shows up; but it seems like it isn't; otherwise my autoresizing mask should have worked.
If the presence of the delete button doesn't cause any views to be resized; is there anyway that I can do this manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用 UIViewAutoresizingFlexibleLeftMargin。
原因如下。您希望内容向左移动,基本上使删除按钮看起来像是将内容推到左侧,使其脱离原来的位置。 flexibleLeftMargin 基本上意味着您的 UILabel 将固定在 contentView 的右侧。您想要这个的原因是因为删除按钮实际上会导致您的 contentView 缩小其宽度。
UILabel 的 autoresizingmask 指的是它在 contentView(而不是单元格)内的行为方式。
尝试一下,应该会有效。
You should use UIViewAutoresizingFlexibleLeftMargin.
Here's why. You want your contents to move to the left, basically making it seem like the delete button is pushing the contents to the left, out of it's way. flexibleLeftMargin basically means your UILabel will stay fixed to the right side of your contentView. The reason you want this, is because the delete button actually causes your contentView to shrink it's width.
The autoresizingmask of your UILabel refers to how it behaves inside the contentView, not the cell.
Give it a try, it should work.
这个问题确实很老了,但我觉得无论如何我都应该回答这个问题,因为我自己刚刚找到了解决方案。
仅单元格的 ContentView 会调整大小并显示确认按钮。如果您不将视图(标签、图像视图等)添加到 cell.contentView 中,而不是直接将它们添加到单元格中,那么当 contentView 调整大小时,它们不会调整大小。就我而言,我将其直接添加到单元格中。
因此,不要做类似的事情:
你应该做:
希望这可以帮助其他偶然发现这个问题的人。
This question is really old but I feel I should answer this anyway since I just found the solution myself.
Only the cell's ContentView gets resized with the confirmation button is shown. If you don't add your views (labels, imageviews, etc...) to the cell.contentView instead of adding them to the cell directly then they won't be resized when the contentView is resized. In my case, I was adding it to the cell directly.
So, instead of doing something like:
you should do:
Hope this helps others who stumble upon this issue.
我使用的是 iOS 7,也遇到了同样的问题。我正在为启用了自动布局的 UITableViewCell 使用单独的 xib,因此只需向标签添加一个约束,以便它在右侧有一个固定的间隙。
I am using iOS 7, I got the same issue. I am using a separate xib for the UITableViewCell with auto layout enabled, so just added one more constraint to the label so that it will have a fixed gap on its right side.