我刚刚在 Xcode 12 上使用 Apple M1 芯片启动了一个新项目。我在安装 Pod 时确实遇到了问题,但我能够使用sudo arch -x86_64 gem install ffithen修复它们arch -x86_64 pod install。现在,我面临的问题是当我添加应用内购买和广告的 admob pod 时。我收到一个错误,指出Cannot find type 'SKProduct' in scope和Cannot find type 'GADInterstitial' in scope。我将“验证工作区”更改为YES“构建设置”,但这并没有解决问题。
我正在尝试扩展多个类,即UIButton和UITextField。它们都具有相同的功能,在我调用该功能时可以摆动。我试图不重复我的代码不止一次。我一直在尝试使用protocal,以便可以扩展并编写所需的函数,然后在类中对其进行扩展,但是问题出在我的函数中,我必须调用self,但是由于self可以仅在UITextField和UIButton上调用。
这是我的代码
import UIKit
extension UIButton {
func wiggle() {
let position = "position"
let wiggleAnimation = CABasicAnimation(keyPath: position)
wiggleAnimation.duration = 0.05
wiggleAnimation.repeatCount = 5
wiggleAnimation.autoreverses = true
wiggleAnimation.fromValue = CGPoint(x: self.center.x - 4.0, y: self.center.y)
wiggleAnimation.toValue = CGPoint(x: self.center.x + 4.0, y: self.center.y)
layer.add(wiggleAnimation, forKey: position)
}
}
extension UITextField {
func wiggle() {
let position = "position"
let wiggleAnimation = CABasicAnimation(keyPath: position)
wiggleAnimation.duration = 0.05
wiggleAnimation.repeatCount = 5
wiggleAnimation.autoreverses = true
wiggleAnimation.fromValue = CGPoint(x: self.center.x - 4.0, y: …Run Code Online (Sandbox Code Playgroud)