【发布时间】:2014-10-22 21:22:57
【问题描述】:
所以我在核心图形中绘制了一些我想在用户按下按钮时旋转的东西。在我的故事板中,我有一个视图和一个按钮。我有一个子类 UIView 的 Cocoa Touch 类,并且 View 的自定义类设置为这个子类。在这里,我有一个属性用于存储我希望绘图旋转的度数。在'- (void)drawRect:(CGRect)rect' 方法中我有
int lineRotate = self.rotationAmount;
UIBezierPath * line = [UIBezierPath bezierPath];
[line moveToPoint:CGPointMake(55.0, 55.0)];
[line addLineToPoint:CGPointMake(55.0, 25.0)];
[line applyTransform:CGAffineTransformMakeTranslation(-55, -55)];
[line applyTransform:CGAffineTransformMakeRotation(lineRotate * M_PI/180)];
[line applyTransform:CGAffineTransformMakeTranslation(55, 55)];
[line setLineWidth: 5.0];
[[UIColor blackColor]setStroke];
[line stroke];
我也有一个公共方法来设置这个 rotationAmount。从我的 ViewController 类中,我导入了我创建的 UIView 子类。我有一个类的属性,我对其进行了初始化,等等。调用此方法来更改旋转量,然后从按钮的 IBAction 中更改 setNeedsDisplay 不会执行任何操作。我需要更改或添加什么才能使按钮正常工作?
【问题讨论】:
标签: ios button rotation core-graphics