为什么不能调用该方法?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么不能调用该方法?相关的知识,希望对你有一定的参考价值。
我刚刚从GitHub克隆了一个项目,并将相关文件夹添加到我的项目中。当我运行我的项目时,动画效果可以正常显示,但动画上的图像无法显示。我已经尝试重新克隆完整的代码,但它仍然做同样的事情。我确信所有的代码和图像都是完全克隆的。
我添加了一个断点,意识到func circleMenu
从未被调用过。有人可以解释一下,或者至少告诉我需要写什么才能使它正确无误?
这是我的代码:
import UIKit
import CircleMenu
extension UIColor {
static func color(_ red: Int, green: Int, blue: Int, alpha: Float) -> UIColor {
return UIColor(
red: 1.0 / 255.0 * CGFloat(red),
green: 1.0 / 255.0 * CGFloat(green),
blue: 1.0 / 255.0 * CGFloat(blue),
alpha: CGFloat(alpha))
}
}
class FirstViewController: UIViewController, CircleMenuDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate{
@IBAction func to2(_ sender: UIButton) {
let sb = UIStoryboard(name:"Main",bundle: Bundle.main)
let view2 = sb.instantiateViewController(withIdentifier: "view2")
layerTransition(animTye: .cube, subType: .ramdom, curve: .EaseInEaseOut, duration: 0.4, layer: (self.view.window?.layer)!)
self.present(view2,animated: true,completion: nil)
}
// let secondView = ViewController()
@IBAction func toView2(_ sender: UIButton) {
let sb = UIStoryboard(name:"Main",bundle: Bundle.main)
let secondViewController = sb.instantiateViewController(withIdentifier: "SecondViewController")
layerTransition(animTye: .cube, subType: .ramdom, curve: .EaseInEaseOut, duration: 0.4, layer: (self.view.window?.layer)!)
self.present(secondViewController,animated: true,completion: nil)
}
var imagePickerController:UIImagePickerController!
enum TransitionAnimType : Int {
case fade = 0,
push,
reveal,
moveIn,
cube,
suckEffect,
oglFlip,
rippleEffect,
pageCurl,
pageUnCurl,
cameraIrisHollowOpen,
cameraIrisHollowClose,
curlDown,
curlUp,
flipFromLeft,
flipFromRight,
ramdom
}
enum TransitionSubType : Int {
case top = 0,
left,
bottom,
right,
ramdom
}
enum TransitionCurve : Int {
case Default = 0,
EaseIn,
EaseOut,
EaseInEaseOut,
Linear,
Ramdom
}
private func animationType(animType: TransitionAnimType) -> String {
let animTypeArray = ["fade", "push", "reveal", "moveIn", "cube", "suckEffect", "oglFlip", "rippleEffect", "pageCurl", "pageUnCurl", "cameraIrisHollowOpen", "cameraIrisHollowClose", "curlDown", "curlUp", "flipFromLeft", "flipFromRight", "ramdom"]
return objectFromDataSource(array: animTypeArray, index: animType.rawValue, isRamdom: (TransitionAnimType.ramdom == animType)) as! String
}
private func animationSubType(subType: TransitionSubType) -> String {
let animSubTypeArray = [CATransitionSubtype.fromTop, CATransitionSubtype.fromLeft, CATransitionSubtype.fromBottom, CATransitionSubtype.fromRight]
return objectFromDataSource(array: animSubTypeArray, index: subType.rawValue, isRamdom: (TransitionSubType.ramdom == subType)) as! String
}
private func animationCurve(curve: TransitionCurve) -> String {
let animCurveArray = [CAMediaTimingFunctionName.default, CAMediaTimingFunctionName.easeIn, CAMediaTimingFunctionName.easeOut, CAMediaTimingFunctionName.easeInEaseOut, CAMediaTimingFunctionName.linear]
return objectFromDataSource(array: animCurveArray, index: curve.rawValue, isRamdom: (TransitionCurve.Ramdom == curve)) as! String
}
private func objectFromDataSource(array: Array<Any>, index: Int, isRamdom: Bool) -> AnyObject {
let count = array.count
let i = isRamdom ? Int(arc4random_uniform(UInt32(count))) : index
return array[i] as AnyObject
}
func layerTransition(animTye: TransitionAnimType, subType: TransitionSubType, curve: TransitionCurve, duration: CGFloat, layer: CALayer) {
let key = "transition"
if layer.animation(forKey: key) != nil {
layer.removeAnimation(forKey: key)
}
let transition = CATransition()
transition.duration = CFTimeInterval(duration)
transition.type = CATransitionType(rawValue: animationType(animType: animTye))
transition.subtype = CATransitionSubtype(rawValue: animationSubType(subType: subType))
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName(rawValue: animationCurve(curve: curve)))
transition.isRemovedOnCompletion = true
layer.add(transition, forKey: key)
}
// let colors = [UIColor.redColor(), UIColor.grayColor(), UIColor.greenColor(), UIColor.purpleColor()]
let items: [(icon: String, color: UIColor)] = [
("icon_home", UIColor(red: 0.19, green: 0.57, blue: 1, alpha: 1)),
("icon_search", UIColor(red: 0.22, green: 0.74, blue: 0, alpha: 1)),
("notifications-btn", UIColor(red: 0.96, green: 0.23, blue: 0.21, alpha: 1)),
("settings-btn", UIColor(red: 0.51, green: 0.15, blue: 1, alpha: 1)),
("nearby-btn", UIColor(red: 1, green: 0.39, blue: 0, alpha: 1))
]
// @IBInspectable var buttonsCount: Int = 3
// @IBInspectable var duration: Double = 2 // circle animation duration
// @IBInspectable var distance: Float = 100 // distance between center button and buttons
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
}
// MARK: <CircleMenuDelegate>
func circleMenu(_: CircleMenu, willDisplay button: UIButton, atIndex: Int) {
button.backgroundColor = items[atIndex].color
button.setImage(UIImage(named: items[atIndex].icon), for: .normal)
let image = UIImage(named:items[atIndex].icon)
// set highlited image
let highlightedImage = UIImage(named: items[atIndex].icon)?.withRenderingMode(.alwaysTemplate)
button.setImage(highlightedImage, for: .highlighted)
button.tintColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
}
func circleMenu(_: CircleMenu, buttonWillSelected _: UIButton, atIndex: Int) {
print("button will selected: (atIndex)")
}
func circleMenu(_: CircleMenu, buttonDidSelected _: UIButton, atIndex: Int) {
// let sb = UIStoryboard(name:"Main",bundle: Bundle.main)
// let secondView = sb.instantiateViewController(withIdentifier: "secondView")
print("button did selected: (atIndex)")
if(atIndex == 0)
{
if(UIImagePickerController.isSourceTypeAvailable(.camera))
{
self.imagePickerController = UIImagePickerController()
self.imagePickerController.delegate = self
self.imagePickerController.allowsEditing = true
self.imagePickerController.sourceType = UIImagePickerController.SourceType.camera
layerTransition(animTye: .cameraIrisHollowOpen, subType: .ramdom, curve: .EaseInEaseOut, duration: 0.4, layer: (self.view.window?.layer)!)
self.present(self.imagePickerController,animated: true,completion: nil)
}
}
}
}
答案
此时您只需申报代表。确保您也设置了委托,否则将不会调用您的委托方法。
以上是关于为什么不能调用该方法?的主要内容,如果未能解决你的问题,请参考以下文章