Skip to content

Commit

Permalink
bugfix / update for Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
daisukes committed May 17, 2019
1 parent 71a630e commit 76f602c
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 103 deletions.
11 changes: 7 additions & 4 deletions HLPDialog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
ja,
Expand Down Expand Up @@ -414,6 +415,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
Expand All @@ -426,7 +428,7 @@
PRODUCT_BUNDLE_IDENTIFIER = org.hulop.HLPDialogTest;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -435,6 +437,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
Expand All @@ -447,7 +450,7 @@
PRODUCT_BUNDLE_IDENTIFIER = org.hulop.HLPDialogTest;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -591,7 +594,7 @@
SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME).h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -620,7 +623,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME).h";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
6 changes: 3 additions & 3 deletions HLPDialog/CustomTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public class CustomLeftTableViewCell: UITableViewCell
required public init(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)!
self.selectionStyle = UITableViewCellSelectionStyle.none
self.selectionStyle = UITableViewCell.SelectionStyle.none
self.initstyle()
}
public override init(style: UITableViewCellStyle, reuseIdentifier: String?)
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
{
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = UITableViewCellSelectionStyle.none
self.selectionStyle = UITableViewCell.SelectionStyle.none

self.initstyle()

Expand Down
20 changes: 10 additions & 10 deletions HLPDialog/DialogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ public class DialogViewController: UIViewController, UITableViewDelegate, UITabl
let setting = NSLocalizedString("SETTING", tableName: nil, bundle: bundle, value: "", comment:"");
let cancel = NSLocalizedString("CANCEL", tableName: nil, bundle: bundle, value: "", comment:"");

let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: setting, style: UIAlertActionStyle.default, handler: { (action) in
let url = URL(string:UIApplicationOpenSettingsURLString)
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: setting, style: UIAlertAction.Style.default, handler: { (action) in
let url = URL(string:UIApplication.openSettingsURLString)
UIApplication.shared.open(url!, options:[:], completionHandler: { (success) in
})
}))
alert.addAction(UIAlertAction(title: cancel, style: UIAlertActionStyle.default, handler: { (action) in
alert.addAction(UIAlertAction(title: cancel, style: UIAlertAction.Style.default, handler: { (action) in
}))
DispatchQueue.main.async(execute: {
self.present(alert, animated: true, completion: {
Expand All @@ -192,13 +192,13 @@ public class DialogViewController: UIViewController, UITableViewDelegate, UITabl
let setting = NSLocalizedString("SETTING", tableName: nil, bundle: bundle, value: "", comment:"");
let cancel = NSLocalizedString("CANCEL", tableName: nil, bundle: bundle, value: "", comment:"");

let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: setting, style: UIAlertActionStyle.default, handler: { (action) in
let url = URL(string:UIApplicationOpenSettingsURLString)
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: setting, style: UIAlertAction.Style.default, handler: { (action) in
let url = URL(string:UIApplication.openSettingsURLString)
UIApplication.shared.open(url!, options:[:], completionHandler: { (success) in
})
}))
alert.addAction(UIAlertAction(title: cancel, style: UIAlertActionStyle.default, handler: { (action) in
alert.addAction(UIAlertAction(title: cancel, style: UIAlertAction.Style.default, handler: { (action) in
}))
DispatchQueue.main.async(execute: {
self.present(alert, animated: true, completion: {
Expand Down Expand Up @@ -331,7 +331,7 @@ public class DialogViewController: UIViewController, UITableViewDelegate, UITabl
override var accessibilityTraits: UIAccessibilityTraits {
set {}
get {
return UIAccessibilityTraitButton
return UIAccessibilityTraits.button
}
}
override func accessibilityElementDidBecomeFocused() {
Expand Down Expand Up @@ -401,7 +401,7 @@ public class DialogViewController: UIViewController, UITableViewDelegate, UITabl
stt.restartRecognize()
stt.delegate?.showText(NSLocalizedString("SPEAK_NOW", tableName: nil, bundle: Bundle(for: type(of: self)), value: "", comment:"Speak Now!"));
stt.delegate?.listen()
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.navigationItem.leftBarButtonItem)
UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: self.navigationItem.leftBarButtonItem)
}
}

Expand Down
41 changes: 22 additions & 19 deletions HLPDialog/stthelper/AnimLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AnimLayer: CALayer {
static let transparent = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0.0).cgColor
var color = blue
var frames:[TimeInterval] = []

override func draw(in ctx: CGContext) {
let fs = self.bounds.size.width
let rect = CGRect(x: (fs-size)/2, y: (fs-size)/2, width: size, height: size)
Expand All @@ -54,15 +55,17 @@ class AnimLayer: CALayer {
ctx.fillPath()
super.draw(in: ctx)

/*
frames.append(Date().timeIntervalSince1970)
let last = Date().timeIntervalSince1970 - 1
while(frames[0] < last) {
frames.removeFirst()
}
*/
//NSLog("\(frames.count) fps")
}
override class func needsDisplay(forKey key: String) -> Bool {
if key == "size" {
if key == "transform.scale" {
return true
}
return super.needsDisplay(forKey: key)
Expand All @@ -71,12 +74,12 @@ class AnimLayer: CALayer {

// animation builders
static func pulse(_ duration:CFTimeInterval, size: CGFloat, scale:CGFloat) -> CAAnimation{
let a = CAKeyframeAnimation(keyPath: "size")
let a = CAKeyframeAnimation(keyPath: "transform.scale")
var v:[CGFloat] = []
var k:[CGFloat] = []
let N = 30
for i in 0..<N+1 {
v.append(size+size*(scale-1)*sin(CGFloat(i)/CGFloat(N)*CGFloat(Double.pi)*2))
v.append((size+size*(scale-1)*sin(CGFloat(i)/CGFloat(N)*CGFloat(Double.pi)*2))/size)
k.append(CGFloat(i)/CGFloat(N))
}
a.values = v
Expand All @@ -85,63 +88,63 @@ class AnimLayer: CALayer {
a.autoreverses = false
a.isRemovedOnCompletion = false;
a.repeatCount = 1
a.fillMode = kCAFillModeBoth;
a.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
a.fillMode = CAMediaTimingFillMode.both;
a.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
return a
}

static func pop(_ duration:CFTimeInterval, scale:CGFloat, x:CGFloat, y:CGFloat, type:String) -> CABasicAnimation{
static func pop(_ duration:CFTimeInterval, scale:CGFloat, x:CGFloat, y:CGFloat, type:CAMediaTimingFunctionName) -> CABasicAnimation{
let a = CABasicAnimation(keyPath: "transform")
a.duration = duration/2;
var tr = CATransform3DIdentity;
a.fromValue = NSValue(caTransform3D: tr)
a.fromValue = tr
tr = CATransform3DTranslate(tr, x, y, 0);
tr = CATransform3DScale(tr, scale, scale, 1);
tr = CATransform3DTranslate(tr, -x, -y, 0);
a.toValue = NSValue(caTransform3D: tr)
a.toValue = tr
a.repeatCount = 1
a.autoreverses = true
a.isRemovedOnCompletion = false;
a.fillMode = kCAFillModeBoth;
a.fillMode = CAMediaTimingFillMode.both;
a.timingFunction = CAMediaTimingFunction(name: type)
return a
}

static func scale(_ duration:CFTimeInterval, current: CGFloat, scale:CGFloat, type:String) -> CABasicAnimation{
let a = CABasicAnimation(keyPath: "size")
static func bounds_size(_ duration:CFTimeInterval, from: CGFloat, to:CGFloat, type:CAMediaTimingFunctionName) -> CABasicAnimation{
let a = CABasicAnimation(keyPath: "bounds.size")
a.duration = duration
a.fromValue = current
a.toValue = current * scale
a.fromValue = CGSize(width: from, height: from)
a.toValue = CGSize(width: to, height: to)
a.repeatCount = 1
a.autoreverses = false
a.isRemovedOnCompletion = false;
a.fillMode = kCAFillModeBoth;
a.fillMode = CAMediaTimingFillMode.both
a.timingFunction = CAMediaTimingFunction(name: type)
return a
}

static func dissolve(_ duration:CFTimeInterval, type:String) -> CABasicAnimation{
static func dissolve(_ duration:CFTimeInterval, type:CAMediaTimingFunctionName) -> CABasicAnimation{
let a = CABasicAnimation(keyPath: "opacity")
a.duration = duration
a.fromValue = 0
a.toValue = 1
a.repeatCount = 1
a.autoreverses = false
a.isRemovedOnCompletion = false;
a.fillMode = kCAFillModeBoth;
a.fillMode = CAMediaTimingFillMode.both;
a.timingFunction = CAMediaTimingFunction(name: type)
return a
}

static func dissolveOut(_ duration:CFTimeInterval, type:String) -> CABasicAnimation{
static func dissolveOut(_ duration:CFTimeInterval, type:CAMediaTimingFunctionName) -> CABasicAnimation{
let a = CABasicAnimation(keyPath: "opacity")
a.duration = duration
a.fromValue = 1
a.toValue = 0
a.repeatCount = 1
a.autoreverses = false
a.isRemovedOnCompletion = false;
a.fillMode = kCAFillModeBoth;
a.fillMode = CAMediaTimingFillMode.both;
a.timingFunction = CAMediaTimingFunction(name: type)
return a
}
Expand All @@ -154,7 +157,7 @@ class AnimLayer: CALayer {
a.toValue = 0
a.autoreverses = true
a.isRemovedOnCompletion = false
a.fillMode = kCAFillModeBoth
a.fillMode = CAMediaTimingFillMode.both
return a
}

Expand Down
Loading

0 comments on commit 76f602c

Please sign in to comment.