gpt4 book ai didi

ios - iOS 8 中的 UIView 动画损坏

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:27 24 4
gpt4 key购买 nike

我有一个自定义表格 View 单元格,在单独的 xib 文件中设计,带有一个名为 unitInfoBtn 的按钮和一个名为 unitVisibilityCheckBox 的按钮。当表格进入编辑模式时,unitInfoBtn disaperas 和 unitVisibilityCheckBox 出现。通过使用以下代码,这在 iOS 7 中运行良好:

-(void)didTransitionToState:(UITableViewCellStateMask)state
{
[super didTransitionToState:state];
//deal with entering and exiting edit mode
if (state == UITableViewCellStateEditingMask) //cell entered edit mode
{
[UIView animateWithDuration:0.2 animations:^{
self.unitInfoBtn.alpha = 0.0;
self.unitInfoBtn.center = CGPointMake(unitInfoBtnOriginalXPos-50.0, self.unitInfoBtn.center.y);
self.unitVisibilityCheckBox.alpha = 1.0;
}];

} else { //cell exited edit mode
[UIView animateWithDuration:0.2 animations:^{
self.unitInfoBtn.alpha = 1.0;
self.unitInfoBtn.center = CGPointMake(unitInfoBtnOriginalXPos, self.unitInfoBtn.center.y);
self.unitVisibilityCheckBox.alpha = 0.0;

}];
}
}

但是,在 iOS 8 上,代码会中断并且 alpha 设置不会更改。我该如何解决这个问题?

最佳答案

一个问题是这段代码总是错误的:

if (state == UITableViewCellStateEditingMask)

顾名思义,UITableViewCellStateEditingMask 是一个位掩码。那是因为 state 是位掩码。您不会将位掩码与 == 进行比较。您正在寻找掩码中的一个特定位。您必须使用按位与并与零进行比较。

if ((state & UITableViewCellStateEditingMask) != 0)

这告诉您 state 中的 Editing 位已设置。如果是,则说明您正在编辑。

state 等于 UITableViewCellStateEditingMask 的可能性很小。这意味着该位被设置而没有其他位。你不能指望那个。我很惊讶这竟然奏效了。

我并不是说这是造成您遇到困难的原因(因为我真的不明白问题出在哪里),但您肯定不能指望您的代码按原样运行。

关于ios - iOS 8 中的 UIView 动画损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26942038/

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