I'm new in Swift, I come from objc .. in fact I need to do a classse in Swift "generic" to be called by my controller of the project done in objc. specifically I have to "replace" the few lines of code in the "Lottie" library for the animations of the project. I need to write only my Swift class methods here in obj c .. can you help me? I created this Swift class but I have crashes on the superView, but I'm not sure that's just the problem ...
this is the code I need to replace in Swift:
LOTAnimationView *lottie1Aux = [LOTAnimationView animationNamed:[dict valueForKey:SLIDER_MAP_IMG_KEY]];
lottie1Aux.contentMode = UIViewContentModeScaleToFill;
lottie1Aux.frame = slide.tutorialImageView.bounds;
lottie1Aux.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
lottie1Aux.loopAnimation = YES;
[slide.tutorialImageView addSubview:mySwiftClass];
and the is the Class Swift that I can make for replace and optimize...
import Foundation
import Lottie
import UIKit
@objc
public class myClass: UIViewController {
var alertView: AnimationView!
override public func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
createView()
}
@objc public func createView() {
// Create a red view
let alertWidth: CGFloat = view.bounds.width
let alertHeight: CGFloat = view.bounds.height
let alertViewFrame: CGRect = CGRect(x: 0, y: 0, width: alertWidth, height: alertHeight)
alertView = UIView(frame: alertViewFrame) as! AnimationView
alertView.backgroundColor = UIColor.red
// Create an image view and add it to this view
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: alertWidth, height: alertHeight/2))
imageView.image = UIImage(named: "tour_merchant_pagamento")
alertView.addSubview(imageView)
//view.addSubview(alertView)
alertView = AnimationView(name: "tour_merchant_pagamento")
alertView.contentMode = UIViewContentMode.scaleToFill
alertView.loopMode = .loop
}