diff --git a/PKHUD.podspec b/PKHUD.podspec index acc86d3..dfabca2 100644 --- a/PKHUD.podspec +++ b/PKHUD.podspec @@ -2,14 +2,15 @@ Pod::Spec.new do |s| s.name = 'PKHUD' s.module_name = 'PKHUD' s.version = '4.2.0' - s.summary = 'A Swift 3 based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8 and up' + s.summary = 'A Swift 3 based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8/macOS 10.11 and up' s.homepage = 'https://github.com/pkluz/PKHUD' s.license = 'MIT' s.author = { 'Philip Kluz' => 'Philip.Kluz@gmail.com' } - s.platform = :ios, '8.0' s.ios.deployment_target = '8.0' + s.osx.deployment_target = '10.11' s.requires_arc = true s.source = { :git => 'https://github.com/pkluz/PKHUD.git', :tag => s.version.to_s } - s.source_files = 'PKHUD/**/*.{h,swift}' + s.source_files = 'PKHUD/**/*.swift' + s.osx.source_files = 'PKHUDMACOS/**/*.swift' s.resources = 'PKHUD/*.xcassets' end diff --git a/PKHUD.xcodeproj/project.pbxproj b/PKHUD.xcodeproj/project.pbxproj index c832c1b..cc5fecf 100644 --- a/PKHUD.xcodeproj/project.pbxproj +++ b/PKHUD.xcodeproj/project.pbxproj @@ -11,7 +11,35 @@ 12CE19F41E25784D0062D873 /* PKHUDDemoUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12CE19F31E25784D0062D873 /* PKHUDDemoUITests.swift */; }; 12CE19FD1E2578680062D873 /* PKHUD.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F996321E19514FD8001F73CA /* PKHUD.framework */; }; 3097AF3A1C4843AE007DD42B /* PKHUDRotatingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3097AF391C4843AE007DD42B /* PKHUDRotatingImageView.swift */; }; + 4F2076D01DCA1D2E006CCD41 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2076CF1DCA1D2E006CCD41 /* AppDelegate.swift */; }; + 4F2076D21DCA1D2E006CCD41 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2076D11DCA1D2E006CCD41 /* ViewController.swift */; }; + 4F2076D41DCA1D2E006CCD41 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4F2076D31DCA1D2E006CCD41 /* Assets.xcassets */; }; + 4F2076D71DCA1D2E006CCD41 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4F2076D51DCA1D2E006CCD41 /* Main.storyboard */; }; + 4F2076E81DCA2397006CCD41 /* PKHUDMACOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 4F2076E61DCA2397006CCD41 /* PKHUDMACOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4F2076EB1DCA2397006CCD41 /* PKHUDMACOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F2076E41DCA2397006CCD41 /* PKHUDMACOS.framework */; }; + 4F2076EC1DCA2397006CCD41 /* PKHUDMACOS.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4F2076E41DCA2397006CCD41 /* PKHUDMACOS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 4F2076F11DCA23FC006CCD41 /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640011551C5B6C080013F32B /* HUD.swift */; }; + 4F2076F21DCA240C006CCD41 /* PKHUD.h in Headers */ = {isa = PBXBuildFile; fileRef = F996322219514FD8001F73CA /* PKHUD.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4F2076F31DCA2413006CCD41 /* PKHUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324819514FEF001F73CA /* PKHUD.swift */; }; + 4F2076F41DCA2416006CCD41 /* PKHUDAssets.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324619514FEF001F73CA /* PKHUDAssets.swift */; }; + 4F2076F61DCA241E006CCD41 /* PKHUDAnimating.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */; }; + 4F2076F71DCA2421006CCD41 /* PKHUDSquareBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B15C1B2B8C20003C3734 /* PKHUDSquareBaseView.swift */; }; + 4F2076F81DCA2425006CCD41 /* PKHUDWideBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B15E1B2B8C7E003C3734 /* PKHUDWideBaseView.swift */; }; + 4F2076F91DCA2425006CCD41 /* PKHUDTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1601B2B8C8E003C3734 /* PKHUDTextView.swift */; }; + 4F2076FA1DCA2425006CCD41 /* PKHUDSystemActivityIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1661B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift */; }; + 4F2076FB1DCA2425006CCD41 /* PKHUDSuccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */; }; + 4F2076FC1DCA2425006CCD41 /* PKHUDErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC41BB852C60015E5A8 /* PKHUDErrorView.swift */; }; + 4F2076FD1DCA2425006CCD41 /* PKHUDProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC71BB85EA70015E5A8 /* PKHUDProgressView.swift */; }; + 4F2076FE1DCA2425006CCD41 /* PKHUDAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12010C891C3D0E8D005DC6FC /* PKHUDAnimation.swift */; }; + 4F2076FF1DCA2425006CCD41 /* PKHUDRotatingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3097AF391C4843AE007DD42B /* PKHUDRotatingImageView.swift */; }; + 4F2077001DCA2429006CCD41 /* FrameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324919514FEF001F73CA /* FrameView.swift */; }; + 4F2077021DCA2430006CCD41 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F996325419514FF3001F73CA /* Images.xcassets */; }; + 4F2077041DCA2638006CCD41 /* NSBezierPath+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2077031DCA2638006CCD41 /* NSBezierPath+.swift */; }; + 4FF09D241DD1BA960010FD7E /* Shim.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF09D231DD1BA960010FD7E /* Shim.swift */; }; 640011571C5B6C080013F32B /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640011551C5B6C080013F32B /* HUD.swift */; }; + DA319B041DD427CB00B60484 /* Shim.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF09D231DD1BA960010FD7E /* Shim.swift */; }; + DAE72D5B1DCAE2EF00538227 /* Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE72D5A1DCAE2EF00538227 /* Window.swift */; }; + DAE72D5C1DCAE52D00538227 /* Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE72D5A1DCAE2EF00538227 /* Window.swift */; }; F908BEC01BB849290015E5A8 /* PKHUDSuccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */; }; F908BEC31BB84D0B0015E5A8 /* PKHUDAnimating.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */; }; F908BEC51BB852C60015E5A8 /* PKHUDErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC41BB852C60015E5A8 /* PKHUDErrorView.swift */; }; @@ -30,8 +58,6 @@ F996324D19514FEF001F73CA /* PKHUDAssets.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324619514FEF001F73CA /* PKHUDAssets.swift */; }; F996324F19514FEF001F73CA /* PKHUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324819514FEF001F73CA /* PKHUD.swift */; }; F996325019514FEF001F73CA /* FrameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324919514FEF001F73CA /* FrameView.swift */; }; - F996325219514FEF001F73CA /* Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324B19514FEF001F73CA /* Window.swift */; }; - F996325319514FEF001F73CA /* WindowRootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996324C19514FEF001F73CA /* WindowRootViewController.swift */; }; F996325519514FF3001F73CA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F996325419514FF3001F73CA /* Images.xcassets */; }; F996325919515052001F73CA /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996325819515052001F73CA /* DemoViewController.swift */; }; /* End PBXBuildFile section */ @@ -51,6 +77,13 @@ remoteGlobalIDString = F996321D19514FD8001F73CA; remoteInfo = PKHUD; }; + 4F2076E91DCA2397006CCD41 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = F99631F419514FAC001F73CA /* Project object */; + proxyType = 1; + remoteGlobalIDString = 4F2076E31DCA2397006CCD41; + remoteInfo = PKHUDMACOS; + }; F996323119514FD8001F73CA /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = F99631F419514FAC001F73CA /* Project object */; @@ -68,6 +101,17 @@ /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ + 4F2076F01DCA2397006CCD41 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 4F2076EC1DCA2397006CCD41 /* PKHUDMACOS.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; F996323A19514FD8001F73CA /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -87,7 +131,19 @@ 12CE19F31E25784D0062D873 /* PKHUDDemoUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKHUDDemoUITests.swift; sourceTree = ""; }; 12CE19F51E25784D0062D873 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3097AF391C4843AE007DD42B /* PKHUDRotatingImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDRotatingImageView.swift; sourceTree = ""; }; + 4F2076CD1DCA1D2E006CCD41 /* PKHUD macOS Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PKHUD macOS Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4F2076CF1DCA1D2E006CCD41 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 4F2076D11DCA1D2E006CCD41 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 4F2076D31DCA1D2E006CCD41 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4F2076D61DCA1D2E006CCD41 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 4F2076D81DCA1D2E006CCD41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4F2076E41DCA2397006CCD41 /* PKHUDMACOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PKHUDMACOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4F2076E61DCA2397006CCD41 /* PKHUDMACOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PKHUDMACOS.h; sourceTree = ""; }; + 4F2076E71DCA2397006CCD41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4F2077031DCA2638006CCD41 /* NSBezierPath+.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSBezierPath+.swift"; sourceTree = ""; }; + 4FF09D231DD1BA960010FD7E /* Shim.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shim.swift; sourceTree = ""; }; 640011551C5B6C080013F32B /* HUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HUD.swift; sourceTree = ""; }; + DAE72D5A1DCAE2EF00538227 /* Window.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Window.swift; sourceTree = ""; }; F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSuccessView.swift; sourceTree = ""; }; F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDAnimating.swift; sourceTree = ""; }; F908BEC41BB852C60015E5A8 /* PKHUDErrorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDErrorView.swift; sourceTree = ""; }; @@ -108,8 +164,6 @@ F996324619514FEF001F73CA /* PKHUDAssets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDAssets.swift; sourceTree = ""; }; F996324819514FEF001F73CA /* PKHUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUD.swift; sourceTree = ""; }; F996324919514FEF001F73CA /* FrameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FrameView.swift; sourceTree = ""; }; - F996324B19514FEF001F73CA /* Window.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Window.swift; sourceTree = ""; }; - F996324C19514FEF001F73CA /* WindowRootViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowRootViewController.swift; sourceTree = ""; }; F996325419514FF3001F73CA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; F996325819515052001F73CA /* DemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -123,6 +177,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4F2076CA1DCA1D2E006CCD41 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F2076EB1DCA2397006CCD41 /* PKHUDMACOS.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4F2076E01DCA2397006CCD41 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; F99631F919514FAC001F73CA /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -150,6 +219,29 @@ path = PKHUDDemoUITests; sourceTree = ""; }; + 4F2076CE1DCA1D2E006CCD41 /* PKHUD macOS Demo */ = { + isa = PBXGroup; + children = ( + 4F2076CF1DCA1D2E006CCD41 /* AppDelegate.swift */, + 4F2076D11DCA1D2E006CCD41 /* ViewController.swift */, + 4F2076D31DCA1D2E006CCD41 /* Assets.xcassets */, + 4F2076D51DCA1D2E006CCD41 /* Main.storyboard */, + 4F2076D81DCA1D2E006CCD41 /* Info.plist */, + ); + name = "PKHUD macOS Demo"; + path = macOSDemo; + sourceTree = ""; + }; + 4F2076E51DCA2397006CCD41 /* PKHUDMACOS */ = { + isa = PBXGroup; + children = ( + 4F2077031DCA2638006CCD41 /* NSBezierPath+.swift */, + 4F2076E61DCA2397006CCD41 /* PKHUDMACOS.h */, + 4F2076E71DCA2397006CCD41 /* Info.plist */, + ); + path = PKHUDMACOS; + sourceTree = ""; + }; F908BEC11BB84D010015E5A8 /* Protocol */ = { isa = PBXGroup; children = ( @@ -161,6 +253,7 @@ F935B15B1B2B8C03003C3734 /* Content Views */ = { isa = PBXGroup; children = ( + DAE72D5A1DCAE2EF00538227 /* Window.swift */, F908BEC11BB84D010015E5A8 /* Protocol */, F935B15C1B2B8C20003C3734 /* PKHUDSquareBaseView.swift */, F935B15E1B2B8C7E003C3734 /* PKHUDWideBaseView.swift */, @@ -181,6 +274,8 @@ F99631FE19514FAC001F73CA /* PKHUD Demo */, F996321F19514FD8001F73CA /* PKHUD */, 12CE19F21E25784D0062D873 /* PKHUDDemoUITests */, + 4F2076CE1DCA1D2E006CCD41 /* PKHUD macOS Demo */, + 4F2076E51DCA2397006CCD41 /* PKHUDMACOS */, F99631FD19514FAC001F73CA /* Products */, ); sourceTree = ""; @@ -191,6 +286,8 @@ F99631FC19514FAC001F73CA /* PKHUD Demo.app */, F996321E19514FD8001F73CA /* PKHUD.framework */, 12CE19F11E25784C0062D873 /* PKHUDDemoUITests.xctest */, + 4F2076CD1DCA1D2E006CCD41 /* PKHUD macOS Demo.app */, + 4F2076E41DCA2397006CCD41 /* PKHUDMACOS.framework */, ); name = Products; sourceTree = ""; @@ -244,8 +341,7 @@ isa = PBXGroup; children = ( F996324919514FEF001F73CA /* FrameView.swift */, - F996324B19514FEF001F73CA /* Window.swift */, - F996324C19514FEF001F73CA /* WindowRootViewController.swift */, + 4FF09D231DD1BA960010FD7E /* Shim.swift */, ); name = Internal; sourceTree = ""; @@ -253,6 +349,15 @@ /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ + 4F2076E11DCA2397006CCD41 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F2076E81DCA2397006CCD41 /* PKHUDMACOS.h in Headers */, + 4F2076F21DCA240C006CCD41 /* PKHUD.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; F996321B19514FD8001F73CA /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -283,6 +388,43 @@ productReference = 12CE19F11E25784C0062D873 /* PKHUDDemoUITests.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; }; + 4F2076CC1DCA1D2E006CCD41 /* PKHUD macOS Demo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4F2076D91DCA1D2E006CCD41 /* Build configuration list for PBXNativeTarget "PKHUD macOS Demo" */; + buildPhases = ( + 4F2076C91DCA1D2E006CCD41 /* Sources */, + 4F2076CA1DCA1D2E006CCD41 /* Frameworks */, + 4F2076CB1DCA1D2E006CCD41 /* Resources */, + 4F2076F01DCA2397006CCD41 /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 4F2076EA1DCA2397006CCD41 /* PBXTargetDependency */, + ); + name = "PKHUD macOS Demo"; + productName = "PKHUD macOS Demo"; + productReference = 4F2076CD1DCA1D2E006CCD41 /* PKHUD macOS Demo.app */; + productType = "com.apple.product-type.application"; + }; + 4F2076E31DCA2397006CCD41 /* PKHUDMACOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4F2076ED1DCA2397006CCD41 /* Build configuration list for PBXNativeTarget "PKHUDMACOS" */; + buildPhases = ( + 4F2076DF1DCA2397006CCD41 /* Sources */, + 4F2076E01DCA2397006CCD41 /* Frameworks */, + 4F2076E11DCA2397006CCD41 /* Headers */, + 4F2076E21DCA2397006CCD41 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PKHUDMACOS; + productName = PKHUDMACOS; + productReference = 4F2076E41DCA2397006CCD41 /* PKHUDMACOS.framework */; + productType = "com.apple.product-type.framework"; + }; F99631FB19514FAC001F73CA /* PKHUD Demo */ = { isa = PBXNativeTarget; buildConfigurationList = F996321319514FAD001F73CA /* Build configuration list for PBXNativeTarget "PKHUD Demo" */; @@ -354,6 +496,7 @@ hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = F99631F319514FAC001F73CA; productRefGroup = F99631FD19514FAC001F73CA /* Products */; @@ -363,6 +506,8 @@ F99631FB19514FAC001F73CA /* PKHUD Demo */, F996321D19514FD8001F73CA /* PKHUD */, 12CE19F01E25784C0062D873 /* PKHUDDemoUITests */, + 4F2076CC1DCA1D2E006CCD41 /* PKHUD macOS Demo */, + 4F2076E31DCA2397006CCD41 /* PKHUDMACOS */, ); }; /* End PBXProject section */ @@ -375,6 +520,23 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4F2076CB1DCA1D2E006CCD41 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F2076D41DCA1D2E006CCD41 /* Assets.xcassets in Resources */, + 4F2076D71DCA1D2E006CCD41 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4F2076E21DCA2397006CCD41 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F2077021DCA2430006CCD41 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; F99631FA19514FAC001F73CA /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -421,6 +583,39 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4F2076C91DCA1D2E006CCD41 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F2076D21DCA1D2E006CCD41 /* ViewController.swift in Sources */, + 4F2076D01DCA1D2E006CCD41 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4F2076DF1DCA2397006CCD41 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F2076FC1DCA2425006CCD41 /* PKHUDErrorView.swift in Sources */, + 4F2076FD1DCA2425006CCD41 /* PKHUDProgressView.swift in Sources */, + 4F2077001DCA2429006CCD41 /* FrameView.swift in Sources */, + 4F2076FE1DCA2425006CCD41 /* PKHUDAnimation.swift in Sources */, + 4F2076F31DCA2413006CCD41 /* PKHUD.swift in Sources */, + 4F2076FF1DCA2425006CCD41 /* PKHUDRotatingImageView.swift in Sources */, + 4F2076F91DCA2425006CCD41 /* PKHUDTextView.swift in Sources */, + 4F2077041DCA2638006CCD41 /* NSBezierPath+.swift in Sources */, + 4F2076F81DCA2425006CCD41 /* PKHUDWideBaseView.swift in Sources */, + 4F2076F61DCA241E006CCD41 /* PKHUDAnimating.swift in Sources */, + 4F2076FB1DCA2425006CCD41 /* PKHUDSuccessView.swift in Sources */, + 4F2076FA1DCA2425006CCD41 /* PKHUDSystemActivityIndicatorView.swift in Sources */, + DAE72D5C1DCAE52D00538227 /* Window.swift in Sources */, + 4F2076F41DCA2416006CCD41 /* PKHUDAssets.swift in Sources */, + 4F2076F11DCA23FC006CCD41 /* HUD.swift in Sources */, + DA319B041DD427CB00B60484 /* Shim.swift in Sources */, + 4F2076F71DCA2421006CCD41 /* PKHUDSquareBaseView.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; F99631F819514FAC001F73CA /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -438,18 +633,18 @@ 640011571C5B6C080013F32B /* HUD.swift in Sources */, 3097AF3A1C4843AE007DD42B /* PKHUDRotatingImageView.swift in Sources */, F935B1611B2B8C8E003C3734 /* PKHUDTextView.swift in Sources */, - F996325319514FEF001F73CA /* WindowRootViewController.swift in Sources */, F908BEC31BB84D0B0015E5A8 /* PKHUDAnimating.swift in Sources */, F908BEC81BB85EA70015E5A8 /* PKHUDProgressView.swift in Sources */, F908BEC01BB849290015E5A8 /* PKHUDSuccessView.swift in Sources */, + 4FF09D241DD1BA960010FD7E /* Shim.swift in Sources */, F908BEC51BB852C60015E5A8 /* PKHUDErrorView.swift in Sources */, F935B15D1B2B8C20003C3734 /* PKHUDSquareBaseView.swift in Sources */, - F996325219514FEF001F73CA /* Window.swift in Sources */, F935B15F1B2B8C7E003C3734 /* PKHUDWideBaseView.swift in Sources */, F996324D19514FEF001F73CA /* PKHUDAssets.swift in Sources */, F996324F19514FEF001F73CA /* PKHUD.swift in Sources */, F935B1671B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift in Sources */, 12010C8A1C3D0E8D005DC6FC /* PKHUDAnimation.swift in Sources */, + DAE72D5B1DCAE2EF00538227 /* Window.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -466,6 +661,11 @@ target = F996321D19514FD8001F73CA /* PKHUD */; targetProxy = 12CE19FB1E2578640062D873 /* PBXContainerItemProxy */; }; + 4F2076EA1DCA2397006CCD41 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 4F2076E31DCA2397006CCD41 /* PKHUDMACOS */; + targetProxy = 4F2076E91DCA2397006CCD41 /* PBXContainerItemProxy */; + }; F996323219514FD8001F73CA /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = F996321D19514FD8001F73CA /* PKHUD */; @@ -478,6 +678,17 @@ }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + 4F2076D51DCA1D2E006CCD41 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4F2076D61DCA1D2E006CCD41 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 12CE19F81E25784D0062D873 /* Debug */ = { isa = XCBuildConfiguration; @@ -515,6 +726,114 @@ }; name = Release; }; + 4F2076DA1DCA1D2E006CCD41 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + INFOPLIST_FILE = macOSDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.NSExceptional.PKHUD-macOS-Demo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + 4F2076DB1DCA1D2E006CCD41 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + INFOPLIST_FILE = macOSDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.NSExceptional.PKHUD-macOS-Demo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; + 4F2076EE1DCA2397006CCD41 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = ""; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = PKHUDMACOS/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.NSExceptional.PKHUDMACOS; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_VERSION = 3.0; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 4F2076EF1DCA2397006CCD41 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = ""; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = PKHUDMACOS/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = com.NSExceptional.PKHUDMACOS; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; F996321119514FAD001F73CA /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -696,6 +1015,24 @@ ); defaultConfigurationIsVisible = 0; }; + 4F2076D91DCA1D2E006CCD41 /* Build configuration list for PBXNativeTarget "PKHUD macOS Demo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4F2076DA1DCA1D2E006CCD41 /* Debug */, + 4F2076DB1DCA1D2E006CCD41 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4F2076ED1DCA2397006CCD41 /* Build configuration list for PBXNativeTarget "PKHUDMACOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4F2076EE1DCA2397006CCD41 /* Debug */, + 4F2076EF1DCA2397006CCD41 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; F99631F719514FAC001F73CA /* Build configuration list for PBXProject "PKHUD" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/PKHUD/FrameView.swift b/PKHUD/FrameView.swift index 5ef1769..ddb0b0e 100644 --- a/PKHUD/FrameView.swift +++ b/PKHUD/FrameView.swift @@ -7,13 +7,25 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// Provides the general look and feel of the PKHUD, into which the eventual content is inserted. -internal class FrameView: UIVisualEffectView { +internal class FrameView: VisualEffectView { + + #if os(OSX) + override internal var isFlipped:Bool { + get { + return true + } + } + #endif internal init() { - super.init(effect: UIBlurEffect(style: .light)) + super.init(effect: BlurEffect(style: .light)) commonInit() } @@ -23,12 +35,13 @@ internal class FrameView: UIVisualEffectView { } fileprivate func commonInit() { - backgroundColor = UIColor(white: 0.8, alpha: 0.36) - layer.cornerRadius = 9.0 - layer.masksToBounds = true - + backgroundColor = Color(white: 0.8, alpha: 0.36) + self.cornerRadius = 9.0 + self.masksToBounds = true + contentView.addSubview(self.content) - + + #if os(iOS) || os(watchOS) let offset = 20.0 let motionEffectsX = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis) @@ -43,10 +56,11 @@ internal class FrameView: UIVisualEffectView { group.motionEffects = [motionEffectsX, motionEffectsY] addMotionEffect(group) + #endif } - - fileprivate var _content = UIView() - internal var content: UIView { + + fileprivate var _content = View() + internal var content: View { get { return _content } @@ -55,7 +69,6 @@ internal class FrameView: UIVisualEffectView { _content = newValue _content.alpha = 0.85 _content.clipsToBounds = true - _content.contentMode = .center frame.size = _content.bounds.size addSubview(_content) } diff --git a/PKHUD/HUD.swift b/PKHUD/HUD.swift index b7815c6..2023788 100644 --- a/PKHUD/HUD.swift +++ b/PKHUD/HUD.swift @@ -7,21 +7,25 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif public enum HUDContentType { case success case error case progress - case image(UIImage?) - case rotatingImage(UIImage?) - + case image(Img?) + case rotatingImage(Img?) + case labeledSuccess(title: String?, subtitle: String?) case labeledError(title: String?, subtitle: String?) case labeledProgress(title: String?, subtitle: String?) - case labeledImage(image: UIImage?, title: String?, subtitle: String?) - case labeledRotatingImage(image: UIImage?, title: String?, subtitle: String?) - + case labeledImage(image: Img?, title: String?, subtitle: String?) + case labeledRotatingImage(image: Img?, title: String?, subtitle: String?) + case label(String?) case systemActivity } @@ -42,9 +46,11 @@ public final class HUD { public static var isVisible: Bool { return PKHUD.sharedHUD.isVisible } // MARK: Public methods, PKHUD based - public static func show(_ content: HUDContentType, onView view: UIView? = nil) { - PKHUD.sharedHUD.contentView = contentView(content) - PKHUD.sharedHUD.show(onView: view) + public static func show(_ content: HUDContentType, onView view: View? = nil) { + let hud = PKHUD.sharedHUD + hud.viewToPresentOn = view + hud.contentView = contentView(content) + hud.show() } public static func hide(_ completion: ((Bool) -> Void)? = nil) { @@ -60,18 +66,18 @@ public final class HUD { } // MARK: Public methods, HUD based - public static func flash(_ content: HUDContentType, onView view: UIView? = nil) { + public static func flash(_ content: HUDContentType, onView view: View? = nil) { HUD.show(content, onView: view) HUD.hide(animated: true, completion: nil) } - - public static func flash(_ content: HUDContentType, onView view: UIView? = nil, delay: TimeInterval, completion: ((Bool) -> Void)? = nil) { + + public static func flash(_ content: HUDContentType, onView view: View? = nil, delay: TimeInterval, completion: ((Bool) -> Void)? = nil) { HUD.show(content, onView: view) HUD.hide(afterDelay: delay, completion: completion) } // MARK: Private methods - fileprivate static func contentView(_ content: HUDContentType) -> UIView { + fileprivate static func contentView(_ content: HUDContentType) -> View { switch content { case .success: return PKHUDSuccessView() diff --git a/PKHUD/PKHUD.swift b/PKHUD/PKHUD.swift index 63a214f..790b96a 100644 --- a/PKHUD/PKHUD.swift +++ b/PKHUD/PKHUD.swift @@ -7,7 +7,11 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// The PKHUD object controls showing and hiding of the HUD, as well as its contents and touch response behavior. open class PKHUD: NSObject { @@ -15,8 +19,8 @@ open class PKHUD: NSObject { fileprivate struct Constants { static let sharedHUD = PKHUD() } - - public var viewToPresentOn: UIView? = nil + + public var viewToPresentOn: View? fileprivate let container = ContainerView() fileprivate var hideTimer: Timer? @@ -40,21 +44,25 @@ open class PKHUD: NSObject { public override init () { super.init() + #if os(iOS) || os(watchOS) NotificationCenter.default.addObserver(self, selector: #selector(PKHUD.willEnterForeground(_:)), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil) + #endif userInteractionOnUnderlyingViewsEnabled = false container.frameView.autoresizingMask = [ .flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin ] + #if os(iOS) || os(watchOS) self.container.isAccessibilityElement = true self.container.accessibilityIdentifier = "PKHUD" + #endif } - - public convenience init(viewToPresentOn view: UIView) { + + public convenience init(viewToPresentOn view: View?) { self.init() viewToPresentOn = view } @@ -76,8 +84,8 @@ open class PKHUD: NSObject { open var isVisible: Bool { return !container.isHidden } - - open var contentView: UIView { + + open var contentView: View { get { return container.frameView.content } @@ -86,7 +94,8 @@ open class PKHUD: NSObject { startAnimatingContentView() } } - + + #if os(iOS) || os(watchOS) open var effect: UIVisualEffect? { get { return container.frameView.effect @@ -95,9 +104,18 @@ open class PKHUD: NSObject { container.frameView.effect = newValue } } - - open func show(onView view: UIView? = nil) { - let view: UIView = view ?? viewToPresentOn ?? UIApplication.shared.keyWindow! + #endif + + open func show() { + #if os(iOS) || os(watchOS) + guard let view = viewToPresentOn ?? UIApplication.shared.keyWindow ?? UIApplication.shared.windows.first else { + preconditionFailure("HUD has no view to present on") + } + #elseif os(OSX) + guard let view = viewToPresentOn ?? NSApplication.shared().orderedWindows.first?.contentView else { + preconditionFailure("HUD has no view to present on") + } + #endif if !view.subviews.contains(container) { view.addSubview(container) container.frame.origin = CGPoint.zero diff --git a/PKHUD/PKHUDAnimating.swift b/PKHUD/PKHUDAnimating.swift index 5ee0857..12591b0 100644 --- a/PKHUD/PKHUDAnimating.swift +++ b/PKHUD/PKHUDAnimating.swift @@ -7,8 +7,6 @@ // Licensed under the MIT license. // -import UIKit - @objc public protocol PKHUDAnimating { func startAnimation() diff --git a/PKHUD/PKHUDAssets.swift b/PKHUD/PKHUDAssets.swift index f9aa00e..b526469 100644 --- a/PKHUD/PKHUDAssets.swift +++ b/PKHUD/PKHUDAssets.swift @@ -7,23 +7,31 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// PKHUDAssets provides a set of default images, that can be supplied to the PKHUD's content views. open class PKHUDAssets: NSObject { - open class var crossImage: UIImage { return PKHUDAssets.bundledImage(named: "cross") } - open class var checkmarkImage: UIImage { return PKHUDAssets.bundledImage(named: "checkmark") } - open class var progressActivityImage: UIImage { return PKHUDAssets.bundledImage(named: "progress_activity") } - open class var progressCircularImage: UIImage { return PKHUDAssets.bundledImage(named: "progress_circular") } + open class var crossImage: Img { return PKHUDAssets.bundledImage(named: "cross") } + open class var checkmarkImage: Img { return PKHUDAssets.bundledImage(named: "checkmark") } + open class var progressActivityImage: Img { return PKHUDAssets.bundledImage(named: "progress_activity") } + open class var progressCircularImage: Img { return PKHUDAssets.bundledImage(named: "progress_circular") } - internal class func bundledImage(named name: String) -> UIImage { + internal class func bundledImage(named name: String) -> Img { let bundle = Bundle(for: PKHUDAssets.self) - let image = UIImage(named: name, in:bundle, compatibleWith:nil) + #if os(iOS) || os(watchOS) + let image = Img(named: name, in: bundle, compatibleWith: nil) + #elseif os(OSX) + let image = bundle.image(forResource: name) + #endif if let image = image { return image } - return UIImage() + return Img() } } diff --git a/PKHUD/PKHUDErrorView.swift b/PKHUD/PKHUDErrorView.swift index 6a27da1..027d962 100644 --- a/PKHUD/PKHUDErrorView.swift +++ b/PKHUD/PKHUDErrorView.swift @@ -7,7 +7,11 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// PKHUDErrorView provides an animated error (cross) view. open class PKHUDErrorView: PKHUDSquareBaseView, PKHUDAnimating { @@ -19,7 +23,7 @@ open class PKHUDErrorView: PKHUDSquareBaseView, PKHUDAnimating { let dash = CAShapeLayer() dash.frame = CGRect(x: 0.0, y: 0.0, width: 88.0, height: 88.0) dash.path = { - let path = UIBezierPath() + let path = BezierPath() path.move(to: CGPoint(x: 0.0, y: 44.0)) path.addLine(to: CGPoint(x: 88.0, y: 44.0)) return path.cgPath @@ -27,7 +31,7 @@ open class PKHUDErrorView: PKHUDSquareBaseView, PKHUDAnimating { dash.lineCap = kCALineCapRound dash.lineJoin = kCALineJoinRound dash.fillColor = nil - dash.strokeColor = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.0).cgColor + dash.strokeColor = Color(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.0).cgColor dash.lineWidth = 6 dash.fillMode = kCAFillModeForwards return dash @@ -35,18 +39,18 @@ open class PKHUDErrorView: PKHUDSquareBaseView, PKHUDAnimating { public init(title: String? = nil, subtitle: String? = nil) { super.init(title: title, subtitle: subtitle) - layer.addSublayer(dashOneLayer) - layer.addSublayer(dashTwoLayer) - dashOneLayer.position = layer.position - dashTwoLayer.position = layer.position + self.addSublayer(dashOneLayer) + self.addSublayer(dashTwoLayer) + dashOneLayer.position = self.center + dashTwoLayer.position = self.center } public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - layer.addSublayer(dashOneLayer) - layer.addSublayer(dashTwoLayer) - dashOneLayer.position = layer.position - dashTwoLayer.position = layer.position + self.addSublayer(dashOneLayer) + self.addSublayer(dashTwoLayer) + dashOneLayer.position = self.center + dashTwoLayer.position = self.center } func rotationAnimation(_ angle: CGFloat) -> CABasicAnimation { diff --git a/PKHUD/PKHUDProgressView.swift b/PKHUD/PKHUDProgressView.swift index 24b7d52..d1ec94b 100644 --- a/PKHUD/PKHUDProgressView.swift +++ b/PKHUD/PKHUDProgressView.swift @@ -7,7 +7,12 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif + import QuartzCore /// PKHUDProgressView provides an indeterminate progress view. @@ -20,9 +25,9 @@ open class PKHUDProgressView: PKHUDSquareBaseView, PKHUDAnimating { public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } - + public func startAnimation() { - imageView.layer.add(PKHUDAnimation.discreteRotation, forKey: "progressAnimation") + imageView.add(PKHUDAnimation.discreteRotation, forKey: "progressAnimation") } public func stopAnimation() { diff --git a/PKHUD/PKHUDRotatingImageView.swift b/PKHUD/PKHUDRotatingImageView.swift index c7eba25..27cd321 100644 --- a/PKHUD/PKHUDRotatingImageView.swift +++ b/PKHUD/PKHUDRotatingImageView.swift @@ -7,14 +7,19 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif + import QuartzCore /// PKHUDRotatingImageView provides a content view that rotates the supplied image automatically. open class PKHUDRotatingImageView: PKHUDSquareBaseView, PKHUDAnimating { - + public func startAnimation() { - imageView.layer.add(PKHUDAnimation.continuousRotation, forKey: "progressAnimation") + imageView.add(PKHUDAnimation.continuousRotation, forKey: "progressAnimation") } public func stopAnimation() { diff --git a/PKHUD/PKHUDSquareBaseView.swift b/PKHUD/PKHUDSquareBaseView.swift index dbcf207..b0bc322 100644 --- a/PKHUD/PKHUDSquareBaseView.swift +++ b/PKHUD/PKHUDSquareBaseView.swift @@ -7,11 +7,17 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif + -/// PKHUDSquareBaseView provides a square view, which you can subclass and add additional views to. -open class PKHUDSquareBaseView: UIView { +/// PKHUDSquareBaseView provides a square view, which you can subclass and add additional views to. +open class PKHUDSquareBaseView: View { + static let defaultSquareBaseViewFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: 156.0, height: 156.0)) public override init(frame: CGRect) { @@ -21,8 +27,16 @@ open class PKHUDSquareBaseView: UIView { public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } + + #if os(OSX) + override open var isFlipped:Bool { + get { + return true + } + } + #endif - public init(image: UIImage? = nil, title: String? = nil, subtitle: String? = nil) { + public init(image: Img? = nil, title: String? = nil, subtitle: String? = nil) { super.init(frame: PKHUDSquareBaseView.defaultSquareBaseViewFrame) self.imageView.image = image titleLabel.text = title @@ -31,31 +45,33 @@ open class PKHUDSquareBaseView: UIView { addSubview(imageView) addSubview(titleLabel) addSubview(subtitleLabel) + + self.layoutIfNeeded() } - open let imageView: UIImageView = { - let imageView = UIImageView() + open let imageView: ImageView = { + let imageView = ImageView() imageView.alpha = 0.85 imageView.clipsToBounds = true imageView.contentMode = .center return imageView }() - - open let titleLabel: UILabel = { - let label = UILabel() + + open let titleLabel: Label = { + let label = Label() label.textAlignment = .center - label.font = UIFont.boldSystemFont(ofSize: 17.0) - label.textColor = UIColor.black.withAlphaComponent(0.85) + label.font = Font.boldSystemFont(ofSize: 17.0) + label.textColor = Color.black.withAlphaComponent(0.85) label.adjustsFontSizeToFitWidth = true label.minimumScaleFactor = 0.25 return label }() - - open let subtitleLabel: UILabel = { - let label = UILabel() + + open let subtitleLabel: Label = { + let label = Label() label.textAlignment = .center - label.font = UIFont.systemFont(ofSize: 14.0) - label.textColor = UIColor.black.withAlphaComponent(0.7) + label.font = Font.systemFont(ofSize: 14.0) + label.textColor = Color.black.withAlphaComponent(0.7) label.adjustsFontSizeToFitWidth = true label.numberOfLines = 2 label.adjustsFontSizeToFitWidth = true @@ -63,6 +79,12 @@ open class PKHUDSquareBaseView: UIView { return label }() + #if os(OSX) + open override var allowsVibrancy: Bool { + return true + } + #endif + open override func layoutSubviews() { super.layoutSubviews() diff --git a/PKHUD/PKHUDSuccessView.swift b/PKHUD/PKHUDSuccessView.swift index adbe3e7..1146d8a 100644 --- a/PKHUD/PKHUDSuccessView.swift +++ b/PKHUD/PKHUDSuccessView.swift @@ -7,13 +7,17 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// PKHUDCheckmarkView provides an animated success (checkmark) view. open class PKHUDSuccessView: PKHUDSquareBaseView, PKHUDAnimating { var checkmarkShapeLayer: CAShapeLayer = { - let checkmarkPath = UIBezierPath() + let checkmarkPath = BezierPath() checkmarkPath.move(to: CGPoint(x: 4.0, y: 27.0)) checkmarkPath.addLine(to: CGPoint(x: 34.0, y: 56.0)) checkmarkPath.addLine(to: CGPoint(x: 88.0, y: 0.0)) @@ -25,21 +29,21 @@ open class PKHUDSuccessView: PKHUDSquareBaseView, PKHUDAnimating { layer.lineCap = kCALineCapRound layer.lineJoin = kCALineJoinRound layer.fillColor = nil - layer.strokeColor = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.0).cgColor + layer.strokeColor = Color(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.0).cgColor layer.lineWidth = 6.0 return layer }() public init(title: String? = nil, subtitle: String? = nil) { super.init(title: title, subtitle: subtitle) - layer.addSublayer(checkmarkShapeLayer) - checkmarkShapeLayer.position = layer.position + self.addSublayer(checkmarkShapeLayer) + checkmarkShapeLayer.position = self.center } public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - layer.addSublayer(checkmarkShapeLayer) - checkmarkShapeLayer.position = layer.position + self.addSublayer(checkmarkShapeLayer) + checkmarkShapeLayer.position = self.center } open func startAnimation() { diff --git a/PKHUD/PKHUDSystemActivityIndicatorView.swift b/PKHUD/PKHUDSystemActivityIndicatorView.swift index c80cd51..36f23a7 100644 --- a/PKHUD/PKHUDSystemActivityIndicatorView.swift +++ b/PKHUD/PKHUDSystemActivityIndicatorView.swift @@ -7,7 +7,11 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// PKHUDSystemActivityIndicatorView provides the system UIActivityIndicatorView as an alternative. public final class PKHUDSystemActivityIndicatorView: PKHUDSquareBaseView, PKHUDAnimating { @@ -28,24 +32,30 @@ public final class PKHUDSystemActivityIndicatorView: PKHUDSquareBaseView, PKHUDA } func commonInit () { - backgroundColor = UIColor.clear - alpha = 0.8 - + self.backgroundColor = Color.clear + self.alpha = 0.8 + self.addSubview(activityIndicatorView) + + self.layoutIfNeeded() } - - public override func layoutSubviews() { - super.layoutSubviews() - activityIndicatorView.center = self.center - } - - let activityIndicatorView: UIActivityIndicatorView = { - let activity = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge) - activity.color = UIColor.black + + let activityIndicatorView: ActivityIndicatorView = { + let activity = ActivityIndicatorView(activityIndicatorStyle: .whiteLarge) + activity.color = Color.black return activity }() - + public func startAnimation() { activityIndicatorView.startAnimating() } + + public override func layoutSubviews() { + super.layoutSubviews() + + let x = (self.frame.width - activityIndicatorView.frame.width) / 2 + let y = (self.frame.height - activityIndicatorView.frame.height) / 2 + + activityIndicatorView.frame.origin = CGPoint(x: x, y: y) + } } diff --git a/PKHUD/PKHUDTextView.swift b/PKHUD/PKHUDTextView.swift index 1bc4991..c5dc44e 100644 --- a/PKHUD/PKHUDTextView.swift +++ b/PKHUD/PKHUDTextView.swift @@ -7,7 +7,11 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// PKHUDTextView provides a wide, three line text view, which you can use to display information. open class PKHUDTextView: PKHUDWideBaseView { @@ -25,6 +29,8 @@ open class PKHUDTextView: PKHUDWideBaseView { func commonInit(_ text: String?) { titleLabel.text = text addSubview(titleLabel) + + layoutIfNeeded() } open override func layoutSubviews() { @@ -32,13 +38,19 @@ open class PKHUDTextView: PKHUDWideBaseView { let padding: CGFloat = 10.0 titleLabel.frame = bounds.insetBy(dx: padding, dy: padding) + + let maxHeight = titleLabel.frame.height + let calcHeight = min(titleLabel.size().height, maxHeight) + let newY = (maxHeight - calcHeight) / 2 + padding + titleLabel.frame.size.height = calcHeight + titleLabel.frame.origin.y = newY } - - open let titleLabel: UILabel = { - let label = UILabel() + + open let titleLabel: Label = { + let label = Label() label.textAlignment = .center - label.font = UIFont.boldSystemFont(ofSize: 17.0) - label.textColor = UIColor.black.withAlphaComponent(0.85) + label.font = Font.labelViewFont + label.textColor = Color.black.withAlphaComponent(0.85) label.adjustsFontSizeToFitWidth = true label.numberOfLines = 3 return label diff --git a/PKHUD/PKHUDWideBaseView.swift b/PKHUD/PKHUDWideBaseView.swift index ea6b6c9..4d79819 100644 --- a/PKHUD/PKHUDWideBaseView.swift +++ b/PKHUD/PKHUDWideBaseView.swift @@ -7,11 +7,15 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// PKHUDWideBaseView provides a wide base view, which you can subclass and add additional views to. -open class PKHUDWideBaseView: UIView { - +open class PKHUDWideBaseView: View { + static let defaultWideBaseViewFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: 265.0, height: 90.0)) public init() { @@ -25,4 +29,10 @@ open class PKHUDWideBaseView: UIView { public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } + + #if os(OSX) + open override var allowsVibrancy: Bool { + return true + } + #endif } diff --git a/PKHUD/Shim.swift b/PKHUD/Shim.swift new file mode 100644 index 0000000..bb59073 --- /dev/null +++ b/PKHUD/Shim.swift @@ -0,0 +1,437 @@ +// +// Extensions-iOS.swift +// PKHUD +// +// Created by Fabian Renner on 08.11.16. +// Copyright © 2016 NSExceptional. All rights reserved. +// +#if os(macOS) + import Cocoa +#else + import UIKit +#endif + +#if os(macOS) + public typealias View = NSView + public typealias Img = NSImage + public typealias Color = NSColor + public typealias VisualEffectView = NSInternalVisualEffectView + public typealias ImageView = NSImageView + public typealias BezierPath = NSBezierPath + public typealias BlurEffect = NSBlurEffect + public typealias Font = NSFont + public typealias ActivityIndicatorView = NSActivityIndicatorView +#else + public typealias View = UIView + public typealias Img = UIImage + public typealias Color = UIColor + public typealias VisualEffectView = UIVisualEffectView + public typealias ImageView = UIImageView + public typealias BezierPath = UIBezierPath + public typealias BlurEffect = UIBlurEffect + public typealias Font = UIFont + public typealias ActivityIndicatorView = UIActivityIndicatorView + public typealias Label = UILabel +#endif + +#if os(macOS) + extension CGColor { + var color: NSColor? { + get { + return NSColor(cgColor: self) + } + } + } + extension NSView { + var backgroundColor: Color { + get { + self.wantsLayer = true + return self.layer?.backgroundColor?.color ?? Color.white + } + set (color) { + self.wantsLayer = true + self.layer?.backgroundColor = color.cgColor + } + } + var alpha: CGFloat { + get { + return self.alphaValue + } + set (alpha) { + self.alphaValue = alpha + } + } + var center: CGPoint { + get { + return CGPoint(x: NSMidX(self.frame), y: NSMidY(self.frame)) + } + set (center) { + self.frame.origin = CGPoint(x: center.x - frame.size.width / 2, + y: center.y - frame.size.height / 2) + } + } + func removeAllAnimations() { + self.wantsLayer = true + self.layer?.removeAllAnimations() + } + + func add(_ anim: CAAnimation, forKey: String?) { + self.wantsLayer = true + self.layer?.anchorPoint = CGPoint(x: 0.5, y: 0.5) + self.layer?.position = CGPoint(x: (self.superview?.frame.width ?? 0)/2, y: (self.superview?.frame.height ?? 0)/2) + self.layer?.add(anim, forKey: forKey) + } + + var clipsToBounds: Bool { + get { + return true + } + set {} + } + + var cornerRadius: CGFloat { + get { + self.wantsLayer = true + return self.layer!.cornerRadius + } + set (radius) { + self.wantsLayer = true + self.layer?.cornerRadius = radius + } + } + + var masksToBounds: Bool { + get { + self.wantsLayer = true + return self.layer!.masksToBounds + } + set (masks) { + self.wantsLayer = true + self.layer?.masksToBounds = masks + } + } + + func addSublayer(_ layer: CALayer) { + self.wantsLayer = true + + layer.anchorPoint = CGPoint(x: 0.5, y: 0.5) + self.layer?.addSublayer(layer) + } + + var position: CGPoint { + get { + self.wantsLayer = true + self.layer?.anchorPoint = CGPoint(x: 0.5, y: 0.5) + return self.layer!.position + } + set { + self.wantsLayer = true + self.layer?.anchorPoint = CGPoint(x: 0.5, y: 0.5) + self.layer?.position = newValue + self.layout() + } + } + + func layoutIfNeeded() { + self.layoutSubviews() + } + + func layoutSubviews() {} + } + + extension NSAutoresizingMaskOptions { + static var flexibleLeftMargin: NSAutoresizingMaskOptions { + get { + return .viewMinXMargin + } + } + static var flexibleRightMargin: NSAutoresizingMaskOptions { + get { + return .viewMaxXMargin + } + } + static var flexibleTopMargin: NSAutoresizingMaskOptions { + get { + return .viewMinYMargin + } + } + static var flexibleBottomMargin: NSAutoresizingMaskOptions { + get { + return .viewMaxYMargin + } + } + static var flexibleHeight: NSAutoresizingMaskOptions { + get { + return .viewHeightSizable + } + } + static var flexibleWidth: NSAutoresizingMaskOptions { + get { + return .viewWidthSizable + } + } + } + extension ContainerView { + var isUserInteractionEnabled: Bool { + get { return self.userInteractionEnabled } + set (userInteraction) { self.userInteractionEnabled = userInteraction } + } + } + + + + + + extension NSImageView { + var contentMode: NSViewContentMode { + get { + switch (self.layer ?? CALayer()).contentsGravity { + default: + return .center + } + } + set { + switch newValue { + case .center: + self.layer?.contentsGravity = kCAGravityCenter + default: + break + } + } + } + } + + extension NSFont { + static var labelViewFont: NSFont { + return NSFont.systemFont(ofSize: 17.0) + } + } + + + //MARK: - shimmed enums ported from iOS + + enum NSViewContentMode : Int { + case scaleToFill + case scaleAspectFit // contents scaled to fit with fixed aspect. remainder is transparent + case scaleAspectFill // contents scaled to fill with fixed aspect. some portion of content may be clipped. + case redraw // redraw on bounds change (calls -setNeedsDisplay) + case center // contents remain same size. positioned adjusted. + case top + case bottom + case left + case right + case topLeft + case topRight + case bottomLeft + case bottomRight + } + + public enum NSActivityIndicatorViewStyle : Int { + case whiteLarge + case white + case gray + } + + public enum NSBlurEffectStyle : Int { + case extraLight + case light + case dark + case regular + case prominent + } + + + // MARK: - Ported classes to be more compatible with iOS apis + + public class NSActivityIndicatorView: NSProgressIndicator { + public init(activityIndicatorStyle style: NSActivityIndicatorViewStyle) { + super.init(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) + + self.wantsLayer = true + self.style = .spinningStyle + } + + public required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func startAnimating() { + self.startAnimation(nil) + } + + var color: Color { + get { + return Color.black + } + set {} + } + } + + public class NSInternalVisualEffectView: NSVisualEffectView { + + public override var frame: NSRect { + didSet { + // update the view mask to reflect the dimensions changes + self.maskImage = self.roundedCornerMaskImage(size: self.frame.size, cornerRadius: 9.0) + } + } + + func roundedCornerMaskImage(size: CGSize, cornerRadius: CGFloat) -> NSImage { + let maskImage = NSImage(size: size, flipped: false) { rect in + let bezierPath = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius) + NSColor.black.set() + bezierPath.fill() + return true + } + return maskImage + } + + init(effect: BlurEffect) { + super.init(frame: NSRect.zero) + + let material: NSVisualEffectMaterial + if case .dark = effect.style { + material = .dark + } else { + material = .light + } + + self.material = material + + if #available(macOS 10.12, *) { + self.blendingMode = .withinWindow + } else { + self.blendingMode = .behindWindow + } + + self.appearance = NSAppearance(named: NSAppearanceNameVibrantLight) + } + + required public init?(coder: NSCoder) { + super.init(coder: coder) + } + var contentView: NSView { + return self + } + } + + public class NSBlurEffect { + let style: NSBlurEffectStyle + public init(style: NSBlurEffectStyle) { + self.style = style + } + } + + open class Label: NSTextField { + override init(frame frameRect: NSRect) { + super.init(frame: frameRect) + + self.isEditable = false + self.isBezeled = false + self.drawsBackground = false + self.isSelectable = false + } + + required public init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + var text: String? { + get { + return self.stringValue + } + set { + self.stringValue = newValue ?? "" + } + } + + var textAlignment: NSTextAlignment { + get { + return self.alignment + } + set { + self.alignment = newValue + } + } + + var adjustsFontSizeToFitWidth: Bool { + get { + return false + } + set {} + } + + var minimumScaleFactor: CGFloat { + get { + return 1 + } + set {} + } + + var numberOfLines: Int { + get { + return self.maximumNumberOfLines + } + set { + self.maximumNumberOfLines = newValue + } + } + + func size() -> CGSize { + return self.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat(Int.max))) + } + } +#else + extension UIView { + func removeAllAnimations() { + layer.removeAllAnimations() + } + + func add(_ anim: CAAnimation, forKey: String?) { + self.layer.add(anim, forKey: forKey) + } + + var cornerRadius: CGFloat { + get { + return self.layer.cornerRadius + } + set (radius) { + self.layer.cornerRadius = radius + } + } + + var masksToBounds: Bool { + get { + return self.layer.masksToBounds + } + set (masks) { + self.layer.masksToBounds = masks + } + } + + func addSublayer(_ layer: CALayer) { + self.layer.addSublayer(layer) + } + + var position: CGPoint { + get { + return self.layer.position + } + set { + self.layer.position = newValue + } + } + } + + extension UILabel { + func size() -> CGSize { + return self.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat(Int.max))) + } + } + + extension UIFont { + static var labelViewFont: UIFont { + return UIFont.boldSystemFont(ofSize: 17.0) + } + } +#endif diff --git a/PKHUD/Window.swift b/PKHUD/Window.swift index 39fff20..935d184 100644 --- a/PKHUD/Window.swift +++ b/PKHUD/Window.swift @@ -7,11 +7,24 @@ // Licensed under the MIT license. // -import UIKit +#if os(iOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import Cocoa +#endif /// The window used to display the PKHUD within. Placed atop the applications main window. -internal class ContainerView: UIView { - +internal class ContainerView: View { + + #if os(OSX) + override internal var isFlipped:Bool { + get { + return true + } + } + var userInteractionEnabled = false + #endif + internal let frameView: FrameView internal init(frameView: FrameView = FrameView()) { self.frameView = frameView @@ -26,21 +39,29 @@ internal class ContainerView: UIView { } fileprivate func commonInit() { - backgroundColor = UIColor.clear + backgroundColor = Color.clear addSubview(backgroundView) addSubview(frameView) } - + #if os(iOS) || os(watchOS) internal override func layoutSubviews() { super.layoutSubviews() + + frameView.center = center + backgroundView.frame = bounds + } + #elseif os(OSX) + override func resizeSubviews(withOldSize oldSize: NSSize) { + super.resizeSubviews(withOldSize: oldSize) frameView.center = center backgroundView.frame = bounds } + #endif internal func showFrameView() { - layer.removeAllAnimations() + removeAllAnimations() frameView.center = center frameView.alpha = 1.0 isHidden = false @@ -64,28 +85,43 @@ internal class ContainerView: UIView { willHide = true if anim { + #if os(iOS) || os(watchOS) UIView.animate(withDuration: 0.8, animations: { self.frameView.alpha = 0.0 self.hideBackground(animated: false) }, completion: { _ in finalize(true) }) + #elseif os(OSX) + NSAnimationContext.runAnimationGroup({ context in + context.duration = 0.8 + self.frameView.animator().alphaValue = 0.0 + self.hideBackground(animated: false) + }, completionHandler: { finalize(true) } ) + #endif } else { self.frameView.alpha = 0.0 finalize(true) } } - - fileprivate let backgroundView: UIView = { - let view = UIView() - view.backgroundColor = UIColor(white:0.0, alpha:0.25) + + fileprivate let backgroundView: View = { + let view = View() + view.backgroundColor = Color(white:0.0, alpha:0.25) view.alpha = 0.0 return view }() internal func showBackground(animated anim: Bool) { if anim { + #if os(iOS) || os(watchOS) UIView.animate(withDuration: 0.175, animations: { self.backgroundView.alpha = 1.0 }) + #elseif os(OSX) + NSAnimationContext.runAnimationGroup({ context in + context.duration = 0.175 + self.backgroundView.animator().alphaValue = 1.0 + }) + #endif } else { backgroundView.alpha = 1.0 } @@ -93,11 +129,28 @@ internal class ContainerView: UIView { internal func hideBackground(animated anim: Bool) { if anim { + #if os(iOS) || os(watchOS) UIView.animate(withDuration: 0.65, animations: { self.backgroundView.alpha = 0.0 + }) + #elseif os(OSX) + NSAnimationContext.runAnimationGroup({ context in + context.duration = 0.65 + self.backgroundView.animator().alphaValue = 0.0 }) + #endif } else { backgroundView.alpha = 0.0 } } + + #if os(macOS) + override func isAccessibilityElement() -> Bool { + return true + } + + override func accessibilityIdentifier() -> String { + return "PKHUD" + } + #endif } diff --git a/PKHUD/WindowRootViewController.swift b/PKHUD/WindowRootViewController.swift deleted file mode 100644 index 2e6d610..0000000 --- a/PKHUD/WindowRootViewController.swift +++ /dev/null @@ -1,46 +0,0 @@ -// -// PKHUD.WindowRootViewController.swift -// PKHUD -// -// Created by Philip Kluz on 6/18/14. -// Copyright (c) 2016 NSExceptional. All rights reserved. -// Licensed under the MIT license. -// - -import UIKit - -/// Serves as a configuration relay controller, tapping into the main window's rootViewController settings. -internal class WindowRootViewController: UIViewController { - - internal override var supportedInterfaceOrientations: UIInterfaceOrientationMask { - if let rootViewController = UIApplication.shared.delegate?.window??.rootViewController { - return rootViewController.supportedInterfaceOrientations - } else { - return UIInterfaceOrientationMask.portrait - } - } - - internal override var preferredStatusBarStyle: UIStatusBarStyle { - return self.presentingViewController?.preferredStatusBarStyle ?? UIApplication.shared.statusBarStyle - } - - internal override var prefersStatusBarHidden: Bool { - return self.presentingViewController?.prefersStatusBarHidden ?? UIApplication.shared.isStatusBarHidden - } - - internal override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { - if let rootViewController = UIApplication.shared.delegate?.window??.rootViewController { - return rootViewController.preferredStatusBarUpdateAnimation - } else { - return .none - } - } - - internal override var shouldAutorotate: Bool { - if let rootViewController = UIApplication.shared.delegate?.window??.rootViewController { - return rootViewController.shouldAutorotate - } else { - return false - } - } -} diff --git a/PKHUDMACOS/Info.plist b/PKHUDMACOS/Info.plist new file mode 100644 index 0000000..3e2c457 --- /dev/null +++ b/PKHUDMACOS/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright © 2016 NSExceptional. All rights reserved. + NSPrincipalClass + + + diff --git a/PKHUDMACOS/NSBezierPath+.swift b/PKHUDMACOS/NSBezierPath+.swift new file mode 100644 index 0000000..bd9790e --- /dev/null +++ b/PKHUDMACOS/NSBezierPath+.swift @@ -0,0 +1,57 @@ +// +// NSBezierPath+.swift +// PKHUD +// +// Created by Fabian Renner on 22.06.16. +// Copyright © 2016 NSExceptional. All rights reserved. +// + +import Foundation + +extension NSBezierPath { + + var cgPath: CGPath { + + get { + return self.transformToCGPathWithoutClosing() + } + } + + /// Transforms the NSBezierPath into a CGPathRef without closing it automatically (hit detection is not needed here + /// + /// :returns: The transformed NSBezierPath + private func transformToCGPathWithoutClosing() -> CGPath { + + // Create path + let path = CGMutablePath() + let points = UnsafeMutablePointer.allocate(capacity: 3) + let numElements = self.elementCount + + if numElements > 0 { + + for index in 0.. + +//! Project version number for PKHUDMACOS. +FOUNDATION_EXPORT double PKHUDMACOSVersionNumber; + +//! Project version string for PKHUDMACOS. +FOUNDATION_EXPORT const unsigned char PKHUDMACOSVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/macOSDemo/AppDelegate.swift b/macOSDemo/AppDelegate.swift new file mode 100644 index 0000000..afba26d --- /dev/null +++ b/macOSDemo/AppDelegate.swift @@ -0,0 +1,26 @@ +// +// AppDelegate.swift +// PKHUD macOS Demo +// +// Created by Fabian Renner on 02.11.16. +// Copyright © 2016 NSExceptional. All rights reserved. +// + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } + + +} + diff --git a/macOSDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/macOSDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..2db2b1c --- /dev/null +++ b/macOSDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/macOSDemo/Base.lproj/Main.storyboard b/macOSDemo/Base.lproj/Main.storyboard new file mode 100644 index 0000000..9edead1 --- /dev/null +++ b/macOSDemo/Base.lproj/Main.storyboard @@ -0,0 +1,877 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macOSDemo/Info.plist b/macOSDemo/Info.plist new file mode 100644 index 0000000..6ab0b68 --- /dev/null +++ b/macOSDemo/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2016 NSExceptional. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + + diff --git a/macOSDemo/ViewController.swift b/macOSDemo/ViewController.swift new file mode 100644 index 0000000..1aa65c2 --- /dev/null +++ b/macOSDemo/ViewController.swift @@ -0,0 +1,94 @@ +// +// ViewController.swift +// PKHUD OSX Demo +// +// Created by Fabian Renner on 22.06.16. +// Copyright © 2016 NSExceptional. All rights reserved. +// + +import Cocoa +import PKHUDMACOS + +class ViewController: NSViewController { + //pure without title and subtitle + + @IBAction func showSuccessHUD(sender: AnyObject) { + HUD.flash(.success, delay: 2.0) + } + + @IBAction func showErrorHUD(sender: AnyObject) { + HUD.flash(.error, delay: 2.0) + } + + @IBAction func showProgressHUD(sender: AnyObject) { + HUD.flash(.progress, delay: 2.0) + } + + @IBAction func showImageHUD(sender: AnyObject) { + HUD.flash(.image(PKHUDAssets.checkmarkImage), delay: 2.0) + } + + @IBAction func showRotatingImageHUD(sender: AnyObject) { + HUD.flash(.rotatingImage(PKHUDAssets.checkmarkImage), delay: 2.0) + } + + + //with title and subtitle + + @IBAction func showLabeledSuccessHUD(sender: AnyObject) { + HUD.flash(.labeledSuccess(title: "Title", subtitle: "Subtitle"), delay: 2.0) + } + + @IBAction func showLabeledErrorHUD(sender: AnyObject) { + HUD.flash(.labeledError(title: "Title", subtitle: "Subtitle"), delay: 2.0) + } + + @IBAction func showLabeledProgressHUD(sender: AnyObject) { + HUD.flash(.labeledProgress(title: "Title", subtitle: "Subtitle"), delay: 2.0) + } + + @IBAction func showLabeledImageHUD(sender: AnyObject) { + HUD.flash(.labeledImage(image: PKHUDAssets.checkmarkImage, title: "Title", subtitle: "Subtitle"), delay: 2.0) + } + + @IBAction func showLabeledRotatingImageHUD(sender: AnyObject) { + HUD.flash(.labeledRotatingImage(image: PKHUDAssets.checkmarkImage, title: "Title", subtitle: "Subtitle"), delay: 2.0) + } + + + //other + + @IBAction func showLabelHUD(sender: AnyObject) { + HUD.flash(.label("Label"), delay: 2.0) + } + + @IBAction func showSystemActivityHUD(sender: AnyObject) { + HUD.flash(.systemActivity, delay: 2.0) + } + + + //mixed + + @IBAction func showProgressThenSuccessHUD(sender: AnyObject) { + HUD.show(.progress) + + // Now some long running task starts... + delay(delay: 2.0) { + // ...and once it finishes we flash the HUD for a second. + HUD.flash(.success, delay: 1.0) + } + } + + @IBAction func showTextWithCompletionHUD(sender: AnyObject) { + HUD.flash(.label("Requesting Licence…"), delay: 2.0) { _ in + print("License Obtained.") + } + } + + + + func delay(delay:Double, closure:@escaping ()->()) { + DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: closure) + } +} +