gpt4 book ai didi

ios - UITableViewCell contentView 框架在编辑模式下向右移动太多

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:53 25 4
gpt4 key购买 nike

我的自定义 UITableViewCell 中有一个 UIImageViewUILabelUIButton。当我将编辑模式设置为 YES 时,整个单元格框架向右移动太多。

上下滚动表格似乎可以解决问题。

但为什么会发生这种情况,我该如何真正解决呢?

最佳答案

在您的自定义 UITableViewCell 中使用 layoutSubviews 和 willTransitionToState。在你的 .h 文件中添加 int state;在您的 .m 单元格中添加

    - (void)willTransitionToState:(UITableViewCellStateMask)aState
{
[super willTransitionToState:aState];
state = aState;
}

同时添加:

    - (void)layoutSubviews
{
[super layoutSubviews];
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing )
{
switch (state) {
case 2:
// swipe action -> here you play with how much your content will move
self.contentView.frame = CGRectMake(90,
self.contentView.frame.origin.y,
self.contentView.frame.size.width-90,
self.contentView.frame.size.height);
break;
}
} else {
NSLog(@"subview not in edit %i",state);
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
[self setNeedsDisplay];
}
}

这应该足以自定义缩进。

关于ios - UITableViewCell contentView 框架在编辑模式下向右移动太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com