gpt4 book ai didi

ios - 在 UITableViewCell 中旋转标签

转载 作者:行者123 更新时间:2023-11-28 12:51:12 26 4
gpt4 key购买 nike

当包含它的单元格被选中时,我试图将 UILabel 旋转 180°。我试过在图层上设置变换,试过 CABasicAnimation 和 UIView.animateWithDuration,但没有成功。

有没有人有过这方面的经验?

我无法调用 reloadData,因为标签位于 Accordion 单元格内,并且选择会导致 Accordion 打开/关闭。 reloadData 覆盖 beginUpdates/endUpdates 的动画。

这是我尝试过的:

func rotate180Degrees(duration: CFTimeInterval = 1.0, completionDelegate: AnyObject? = nil) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI)
rotateAnimation.duration = duration

if let delegate: AnyObject = completionDelegate {
rotateAnimation.delegate = delegate
}
self.layer.addAnimation(rotateAnimation, forKey: nil)
}

还有这个:

UIView.animateWithDuration(0.1) {
cell.chevronLabel.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}

如果相关的话,这是我的细胞模型:

class SideMenuAccountTypeCell: UITableViewCell {
@IBOutlet weak var accountLabel: UILabel!
@IBOutlet weak var abbreviationLabel: UILabel!
@IBOutlet weak var circleView: CircleView!
@IBOutlet weak var chevronLabel: UILabel!

private (set) var items = [Item]()

class Item {
var isHidden: Bool
var value: AnyObject

init(_ hidden: Bool = true, value: AnyObject) {
self.isHidden = hidden
self.value = value
}
}

class HeaderItem: Item {
init (value: AnyObject) {
super.init(false, value: value)
}
}

func append(item: Item) {
self.items.append(item)
}

func removeAll() {
self.items.removeAll()
}

func expand(headerIndex: Int) {
self.toggleVisible(headerIndex, isHidden: false)
}

func collapse(headerIndex: Int) {
self.toggleVisible(headerIndex, isHidden: true)
}

private func toggleVisible(headerIndex: Int, isHidden: Bool) {
var header = headerIndex
header += 1

while header < self.items.count && !(self.items[header] is HeaderItem) {
self.items[header].isHidden = isHidden

header += 1
}
}
}

最佳答案

在你的 didSelectRowAtIndexPath 中试试这个

    SideMenuAccountTypeCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath];

//transform to flips on y-axis
CATransform3D tfm = CATransform3DMakeRotation(M_PI, 0.0f, -1.0f, 0.0f);

//apply the transform before the animation so that the label remains in the same state on completion
cell.chevronLabel.layer.transform = tfm;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.5f;
animation.beginTime = 0.0f;
//apply a little perspective
tfm.34 = 0.001f
tfm.m14 = -0.001f;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:tfm];
[cell.chevronLabel.layer addAnimation:animation forKey:@"rotateTheLabel"];

关于ios - 在 UITableViewCell 中旋转标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36475747/

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