Swift遇到的一些问题

一,手动导入Alamofire和Kingfisher库,两文件重复,RedirectHandler,SessionDelegate,需要对Kingfisher库文件进行重命名,这样是改动最少的:

1,将RedirectHandler.swift文件名直接改为KingfisherRedirectHandler.swift。
2,将SessionDelegate.swift改为KingfisherSessionDelegate.swift,然后在其类中:
第31行,class KingfisherSessionDelegate: NSObject;
第150行,extension KingfisherSessionDelegate: URLSessionDataDelegate。
3,在Kingfisher库中的ImageDownloader.swift文件中:
第140行,private let sessionDelegate: KingfisherSessionDelegate;
第156行,sessionDelegate = KingfisherSessionDelegate()。

二,Swift项目导入SDWebImage使用。

下载SDWebImage,https://github.com/rs/SDWebImage
并且找到当前库源码,然后Add Files to “xxx.project”……;
创建一个.h文件,命名为SDWebImage+Header.h,
内部为:

#ifndef SDWebImage_Header_h
#define SDWebImage_Header_h
#import "UIImageView+WebCache.h"
#endif /* SDWebImage_Header_h */

找到Target – Build Setting – Swift Comppilier,设置其Objective-C Bridging Header,将其DWebImage+Header.h所在当前项目中的地址加进去即可。

三,swift,CATransaction动画事务。

    @objc func singAction(_ tap: UITapGestureRecognizer) -> Void{
        if let act = action,let tg = target{
            CATransaction.begin()
            let shake: CABasicAnimation = CABasicAnimation(keyPath: "opacity");
            shake.autoreverses = true;
            shake.repeatCount = 0;
            shake.speed = 2.5;
            shake.duration = 0.35;
            shake.fromValue = 1.0;
            shake.toValue = 0.0;
            shake.isRemovedOnCompletion = false;
            CATransaction.setCompletionBlock({
                () -> Void in
                if false == self.operateValid {
                    self.operateValid = true;
                    _ = tg.perform(act, with: self)
                    self.perform(#selector(self.settingOperateValid(_ :)), with: false, afterDelay: TimeInterval(self.operateInterval));
                }else{
                    print("点击的太快了");
                }
            })
            layer.add(shake, forKey: "opacity");
            CATransaction.commit()
        }
    }

四,swift里边如果要用KVO监听属性,属性的修饰必须如下:
@objc dynamic var isKeep: Bool = false;
需要@objc dynamic去修饰;

Leave a Reply

Required fields are marked *