- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何将下面的动画翻译成Swift3?
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(2.5, 2.5, 1)];
我目前拥有的是
let circleEnlargeAnimation = CABasicAnimation(keyPath: "transform.scale")
circleEnlargeAnimation.fromValue = CATransform3DIdentity
circleEnlargeAnimation.toValue = CATransform3DMakeScale(10.0, 10.0, 1.0)
但是我的动画不工作......下面是完整的动画代码:
let shapeLayer = CAShapeLayer()
let center = CGPoint(x: sampleButton.bounds.width/2.0, y: sampleButton.bounds.height/2.0)
let radius = CGFloat(10.0)
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0.0, endAngle: (CGFloat(360.0 * M_PI) / 180.0), clockwise: true)
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor.white.cgColor
shapeLayer.strokeColor = UIColor.white.cgColor
shapeLayer.lineCap = kCALineCapRound
shapeLayer.frame = sampleButton.bounds
let circleEnlargeAnimation = CABasicAnimation(keyPath: "transform.scale")
circleEnlargeAnimation.fromValue = CATransform3DIdentity
circleEnlargeAnimation.toValue = CATransform3DMakeScale(10.0, 10.0, 1.0)
circleEnlargeAnimation.duration = 1.0
shapeLayer.add(circleEnlargeAnimation, forKey: nil)
sampleButton.layer.addSublayer(shapeLayer)
它只显示一个圆圈但没有动画......
最佳答案
您应该使用带有标量数值的键 transform.scale
或带有矩阵值的 transform
。参见 Key Value Coding Extensions in Core Animation Programming Guide获取可用 key 的完整列表。
您可以创建一个矩阵值,例如:
NSValue(caTransform3D:CATransform3DMakeScale(10.0, 10.0, 1.0))
关于ios - NSValue valueWithCATransform3D : in Swift3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40298678/
如何创建包含 CGAffineTransform 的 NSValue 实例? UIKit 提供了[NSValue valueWithCGAffineTransform:],但 AppKit 没有。 我
所以我在这里读到,我可以使用将 CGLayerRef 编码为 NSValue NSValue *myCopy = [[NSValue alloc] initWithBytes:&myLayer obj
如何将非对象 Objective-C 不透明数据类型(如 CGImageRef、CGPDFPageRef)不透明类型转换为 NSValue 对象? 最佳答案 Check out this refere
我正在尝试创建一个跨平台的 NSValue 类别,它将处理 Cocoa 和 iOS 的 CGPoint/NSPoint 和 CGSize/NSSize 等。 我有这个: #ifdef __MAC_OS
我正在尝试将多维结构数组编码到 NSValue 中。 这是结构: typedef struct { float Position[3]; float Color[4]; } Verte
我在 XCode 中收到警告说 NSValue 可能不会响应 +valueWithCMTime:' 但我不确定我做错了什么。在我的头文件中,我有这个: #import #import ... -(
在我需要将所有数据成员保存在 NSDictionary 中的情况下,放置结构(自定义类型,甚至是标量,即 CGPoint)是否更有意义在我自己的包装器中(不是 NSValue),这样我就可以避免每次获
如何将下面的动画翻译成Swift3? CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"trans
我有一个 MVC 应用程序。该模型有一个属性,它是一个结构 NSSize。它可以这样写: - (void)setSize:(NSSize)aSize; View 使用键值编码设置此 NSSize。但是
我通过 NSValue 对象和以下代码行将 Chipmunk Physics 的 cpShape 对象存储在 NSMutableDictionary 中: NSValue *shapeValue =
我正在尝试使用 Facebook pop POPSpringAnimation 为 UIButton 的边界设置动画,但我找不到我应该在 swift 中使用什么来替换 NSValue.valueWit
我有一个 plist(在 XCode 中创建),其中包含一个充满“数字”(0.01、1、2、6)的数组,当使用 initWithContentsOfFile 重新构建时,该数组将解包到 NSValue
有什么方法可以使用 NSKeyedArchiver 来编码包含自定义结构的 NSValue 吗?我有一个 NSDictionary,其中包含封装在 NSValues 中的结构,我想将其存档为更大的对象
一些背景... 我正在编写通过 ObjC-JS 桥使用 UIWebView 与 javascript 交互的代码的stringByEvaluatingJavaScriptFromString: .这个
我正在尝试更改我的 UISegmentedControl 的文本阴影位置.为此,documentation说我需要通过 NSValue它包装了一个 UIOffset 结构。 UITextAttribu
我有一些代码,我将在其中接收未知类型的对象。它可以是 NSString、NSNumber、包裹在 NSValue 或其他类中的标量: -(void) doSomethingWith:(id) valu
如何将NSValue转换为CLLocationCoordinate2D? 我在 (NSArray *)coordinateArray 中收到 NSValue,并且需要为数组中的每个 NSValue 获
我需要将结构 AudioStreamBasicDescription 传递给随机 View Controller 。为此,我创建了一个单例类,我想将 AudioStreamBasicDescripti
我想将 NSValue 转换为 NSNumber。这段代码有什么问题? char value[4]; [myNSValue getValue:(void*)value]; NSNumber *numb
我只是想将 CLLocationCoordinates 转换为 NSValue 以用于稍后在我的应用程序中带回的数组。这是我的代码: NSUInteger count = [self.locati
我是一名优秀的程序员,十分优秀!