├── BuildAnInfiniteCarousel
├── BuildAnInfiniteCarousel.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── JohnLui.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── JohnLui.xcuserdatad
│ │ └── xcschemes
│ │ ├── BuildAnInfiniteCarousel.xcscheme
│ │ └── xcschememanagement.plist
└── BuildAnInfiniteCarousel
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Contents.json
│ ├── pic1.imageset
│ │ ├── Contents.json
│ │ └── pic1@2x.jpg
│ ├── pic2.imageset
│ │ ├── Contents.json
│ │ └── pic2@2x.jpg
│ ├── pic3.imageset
│ │ ├── Contents.json
│ │ └── pic3@2x.jpg
│ └── pic4.imageset
│ │ ├── Contents.json
│ │ └── pic4@2x.jpg
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ └── ViewController.swift
├── BuildYourHTTPRequestLibrary
├── BuildYourHTTPRequestLibrary.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── BuildYourHTTPRequestLibrary.xccheckout
│ │ └── xcuserdata
│ │ │ ├── JohnLui.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ │ │ └── dren_a.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ ├── JohnLui.xcuserdatad
│ │ └── xcschemes
│ │ │ ├── BuildYourHTTPRequestLibrary.xcscheme
│ │ │ └── xcschememanagement.plist
│ │ └── dren_a.xcuserdatad
│ │ └── xcschemes
│ │ ├── BuildYourHTTPRequestLibrary.xcscheme
│ │ └── xcschememanagement.plist
├── BuildYourHTTPRequestLibrary
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ │ ├── LaunchScreen.xib
│ │ └── Main.storyboard
│ ├── Images.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Info.plist
│ ├── Network.swift
│ └── ViewController.swift
├── BuildYourHTTPRequestLibraryTests
│ ├── BuildYourHTTPRequestLibraryTests.swift
│ └── Info.plist
├── Pitaya.png
└── lvwenhancom.cer
├── BuildYourOwnHybridDevelopmentFramework
├── BuildYourOwnHybridDevelopmentFramework.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── JohnLui.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── JohnLui.xcuserdatad
│ │ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ ├── BuildYourOwnHybridDevelopmentFramework.xcscheme
│ │ └── xcschememanagement.plist
├── BuildYourOwnHybridDevelopmentFramework
│ ├── Accelerometer.swift
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ ├── Console.swift
│ ├── Info.plist
│ └── ViewController.swift
├── BuildYourOwnHybridDevelopmentFrameworkTests
│ ├── BuildYourOwnHybridDevelopmentFrameworkTests.swift
│ └── Info.plist
└── www
│ └── plugins
│ ├── Accelerometer.js
│ ├── Base.js
│ └── Console.js
├── ControlOrientation
├── ControlOrientation.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── ControlOrientation.xccheckout
│ │ └── xcuserdata
│ │ │ ├── JohnLui.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ │ │ └── dren_a.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ ├── JohnLui.xcuserdatad
│ │ └── xcschemes
│ │ │ ├── ControlOrientation.xcscheme
│ │ │ └── xcschememanagement.plist
│ │ └── dren_a.xcuserdatad
│ │ └── xcschemes
│ │ ├── ControlOrientation.xcscheme
│ │ └── xcschememanagement.plist
└── ControlOrientation
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ ├── NavigationController.swift
│ ├── SecondViewController.swift
│ ├── TabBarController.swift
│ └── ViewController.swift
├── DifferentWaysToBuildTheUserInterface
├── DifferentWaysToBuildTheUserInterface.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── DifferentWaysToBuildTheUserInterface.xccheckout
│ │ └── xcuserdata
│ │ │ ├── JohnLui.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ │ │ └── dren_a.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ ├── JohnLui.xcuserdatad
│ │ └── xcschemes
│ │ │ ├── DifferentWaysToBuildTheUserInterface.xcscheme
│ │ │ └── xcschememanagement.plist
│ │ └── dren_a.xcuserdatad
│ │ └── xcschemes
│ │ ├── DifferentWaysToBuildTheUserInterface.xcscheme
│ │ └── xcschememanagement.plist
├── DifferentWaysToBuildTheUserInterface
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ │ ├── LaunchScreen.xib
│ │ └── Main.storyboard
│ ├── Button.xib
│ ├── Images.xcassets
│ │ ├── 80.imageset
│ │ │ ├── Contents.json
│ │ │ └── gold@2x.png
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Info.plist
│ ├── Second.storyboard
│ └── ViewController.swift
└── DifferentWaysToBuildTheUserInterfaceTests
│ ├── DifferentWaysToBuildTheUserInterfaceTests.swift
│ └── Info.plist
├── EasyFormValidator
├── EasyFormValidator.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ ├── JohnLui.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ │ │ └── dren_a.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ ├── JohnLui.xcuserdatad
│ │ └── xcschemes
│ │ │ ├── EasyFormValidator.xcscheme
│ │ │ └── xcschememanagement.plist
│ │ └── dren_a.xcuserdatad
│ │ └── xcschemes
│ │ ├── EasyFormValidator.xcscheme
│ │ └── xcschememanagement.plist
└── EasyFormValidator
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ └── ViewController.swift
├── README.md
└── TestReflection
├── TestReflection.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ ├── JohnLui.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ │ └── dren_a.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ ├── JohnLui.xcuserdatad
│ └── xcschemes
│ │ ├── TestReflection.xcscheme
│ │ └── xcschememanagement.plist
│ └── dren_a.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── TestReflection.xcscheme
│ └── xcschememanagement.plist
├── TestReflection
├── AppDelegate.swift
├── Base.lproj
│ ├── LaunchScreen.xib
│ └── Main.storyboard
├── Console.swift
├── Images.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Info.plist
├── ViewController.swift
└── plugins.xml
├── TestReflectionTests
├── Info.plist
└── TestReflectionTests.swift
└── www
├── index.html
└── js
├── jquery-1.9.1.min.js
└── main.js
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/BuildAnInfiniteCarousel.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | BuildAnInfiniteCarousel.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | C8BB2A6E1BE1351900D8B036
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // BuildAnInfiniteCarousel
4 | //
5 | // Created by 吕文翰 on 15/10/29.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic1.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "pic1@2x.jpg",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic1.imageset/pic1@2x.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic1.imageset/pic1@2x.jpg
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic2.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "pic2@2x.jpg",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic2.imageset/pic2@2x.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic2.imageset/pic2@2x.jpg
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic3.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "pic3@2x.jpg",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic3.imageset/pic3@2x.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic3.imageset/pic3@2x.jpg
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic4.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "pic4@2x.jpg",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic4.imageset/pic4@2x.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Assets.xcassets/pic4.imageset/pic4@2x.jpg
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/BuildAnInfiniteCarousel/BuildAnInfiniteCarousel/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // BuildAnInfiniteCarousel
4 | //
5 | // Created by 吕文翰 on 15/10/29.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController, UIScrollViewDelegate {
12 |
13 | @IBOutlet weak var scrollView: UIScrollView!
14 | @IBOutlet weak var pageControl: UIPageControl!
15 | override func viewDidLoad() {
16 | super.viewDidLoad()
17 |
18 | let width = UIScreen.mainScreen().bounds.width
19 | let height = width/2
20 |
21 | for i in 0...5 {
22 | let iv = UIImageView(frame: CGRectMake(width * CGFloat(i), 0, width, height))
23 | var picName = "pic"
24 | switch i {
25 | case 0:
26 | picName += "4"
27 | case 5:
28 | picName += "1"
29 | default:
30 | picName += i.description
31 | }
32 | iv.image = UIImage(named: picName)
33 | iv.contentMode = UIViewContentMode.ScaleAspectFill
34 | iv.clipsToBounds = true
35 | iv.userInteractionEnabled = true
36 | self.scrollView.addSubview(iv)
37 | }
38 | self.scrollView.contentSize = CGSizeMake(width * 6, height)
39 | self.scrollView.contentOffset = CGPointMake(width, 0)
40 | }
41 |
42 | override func didReceiveMemoryWarning() {
43 | super.didReceiveMemoryWarning()
44 | // Dispose of any resources that can be recreated.
45 | }
46 |
47 | func scrollViewDidScroll(scrollView: UIScrollView) {
48 | if scrollView == self.scrollView {
49 | let width = UIScreen.mainScreen().bounds.width
50 | let offsetX = scrollView.contentOffset.x
51 |
52 | if offsetX == 0 {
53 | scrollView.contentOffset = CGPointMake(width * CGFloat(4), 0)
54 | }
55 | if offsetX == width * CGFloat(4 + 1) {
56 | scrollView.contentOffset = CGPointMake(width, 0)
57 | }
58 |
59 | // 此处不能用 offsetX 代替 scrollView.contentOffset.x,这个值在变化
60 | let currentPage = scrollView.contentOffset.x / width - 0.5
61 | self.pageControl.currentPage = Int(currentPage)
62 | }
63 | }
64 |
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/project.xcworkspace/xcshareddata/BuildYourHTTPRequestLibrary.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | CAC7FCA6-585B-46EF-ACE4-DA3B61DF321C
9 | IDESourceControlProjectName
10 | BuildYourHTTPRequestLibrary
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
14 | github.com:johnlui/Swift-On-iOS.git
15 |
16 | IDESourceControlProjectPath
17 | BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
21 | ../../..
22 |
23 | IDESourceControlProjectURL
24 | github.com:johnlui/Swift-On-iOS.git
25 | IDESourceControlProjectVersion
26 | 111
27 | IDESourceControlProjectWCCIdentifier
28 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
36 | IDESourceControlWCCName
37 | Swift%20On%20iOS
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/BuildYourHTTPRequestLibrary.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | BuildYourHTTPRequestLibrary.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 463BF7381B0B299300D669DE
16 |
17 | primary
18 |
19 |
20 | 463BF74D1B0B299300D669DE
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/BuildYourHTTPRequestLibrary.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
75 |
77 |
83 |
84 |
85 |
86 |
87 |
88 |
94 |
96 |
102 |
103 |
104 |
105 |
107 |
108 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | BuildYourHTTPRequestLibrary.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 463BF7381B0B299300D669DE
16 |
17 | primary
18 |
19 |
20 | 463BF74D1B0B299300D669DE
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // BuildYourHTTPRequestLibrary
4 | //
5 | // Created by JohnLui on 15/5/19.
6 | // Copyright (c) 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSAppTransportSecurity
6 |
7 | NSAllowsArbitraryLoads
8 |
9 |
10 | CFBundleDevelopmentRegion
11 | en
12 | CFBundleExecutable
13 | $(EXECUTABLE_NAME)
14 | CFBundleIdentifier
15 | com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)
16 | CFBundleInfoDictionaryVersion
17 | 6.0
18 | CFBundleName
19 | $(PRODUCT_NAME)
20 | CFBundlePackageType
21 | APPL
22 | CFBundleShortVersionString
23 | 1.0
24 | CFBundleSignature
25 | ????
26 | CFBundleVersion
27 | 1
28 | LSRequiresIPhoneOS
29 |
30 | UILaunchStoryboardName
31 | LaunchScreen
32 | UIMainStoryboardFile
33 | Main
34 | UIRequiredDeviceCapabilities
35 |
36 | armv7
37 |
38 | UISupportedInterfaceOrientations
39 |
40 | UIInterfaceOrientationPortrait
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // BuildYourHTTPRequestLibrary
4 | //
5 | // Created by JohnLui on 15/5/19.
6 | // Copyright (c) 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | // Do any additional setup after loading the view, typically from a nib.
16 | }
17 |
18 | override func didReceiveMemoryWarning() {
19 | super.didReceiveMemoryWarning()
20 | // Dispose of any resources that can be recreated.
21 | }
22 |
23 | @IBAction func mainButtonBeTapped(sender: AnyObject) {
24 | let network = NetworkManager(url: "https://www.baidu.com/", method: "GET") { (data, response, error) -> Void in
25 | if let _ = error {
26 | NSLog(error.description)
27 | } else {
28 | print("证书正确!")
29 | }
30 | }
31 | let certData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("lvwenhancom", ofType: "cer")!)!
32 | network.addSSLPinning(LocalCertData: certData) { () -> Void in
33 | print("SSL 证书错误,遭受中间人攻击!")
34 | }
35 | network.fire()
36 |
37 |
38 | let url = "http://staticonsae.sinaapp.com/pitaya.php"
39 |
40 | Network.post(url, callback: { (data, response, error) -> Void in
41 | print("POST 1 请求成功")
42 | })
43 | Network.post(url, params: ["post": "POST Network"], callback: { (data, response, error) -> Void in
44 | let string = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
45 | print("POST 2 请求成功 " + string)
46 | })
47 |
48 | Network.get(url, callback: { (data, response, error) -> Void in
49 | print("GET 1 请求成功")
50 | })
51 | Network.get(url, params: ["get": "POST Network"], callback: { (data, response, error) -> Void in
52 | let string = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
53 | print("GET 2 请求成功 " + string)
54 | })
55 |
56 | Network.request("GET", url: url, params: ["get": "Request Network"]) { (data, response, error) -> Void in
57 | let string = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
58 | print("Request 请求成功 " + string)
59 | }
60 |
61 | let file = File(name: "file", url: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Pitaya", ofType: "png")!))
62 | Network.request("POST", url: "http://staticonsae.sinaapp.com/pitaya.php", files: [file]) { (data, response, error) -> Void in
63 | let string = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
64 | if string == "1" {
65 | print("上传文件成功!")
66 | }
67 | }
68 | }
69 |
70 | }
71 |
72 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibraryTests/BuildYourHTTPRequestLibraryTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // BuildYourHTTPRequestLibraryTests.swift
3 | // BuildYourHTTPRequestLibraryTests
4 | //
5 | // Created by JohnLui on 15/5/19.
6 | // Copyright (c) 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import XCTest
11 |
12 | class BuildYourHTTPRequestLibraryTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | XCTAssert(true, "Pass")
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock() {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibraryTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/Pitaya.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildYourHTTPRequestLibrary/Pitaya.png
--------------------------------------------------------------------------------
/BuildYourHTTPRequestLibrary/lvwenhancom.cer:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildYourHTTPRequestLibrary/lvwenhancom.cer
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/BuildYourOwnHybridDevelopmentFramework.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | BuildYourOwnHybridDevelopmentFramework.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | C8B9327B1B94C45F007DDEBB
16 |
17 | primary
18 |
19 |
20 | C8B9328F1B94C45F007DDEBB
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/Accelerometer.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Accelerometer.swift
3 | // BuildYourOwnHybridDevelopmentFramework
4 | //
5 | // Created by 吕文翰 on 15/9/3.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | import CoreMotion
11 |
12 | class Accelerometer: Plugin {
13 | var motionManager: CMMotionManager!
14 |
15 | var isRunning = false
16 |
17 | // defaults to 10 msec
18 | let kAccelerometerInterval: NSTimeInterval = 10
19 | // g constant: -9.81 m/s^2
20 | let kGravitationalConstant = -9.81
21 |
22 | func getCurrentAcceleration() {
23 | if motionManager == nil {
24 | motionManager = CMMotionManager()
25 | }
26 | if motionManager.accelerometerAvailable {
27 | motionManager.accelerometerUpdateInterval = self.kAccelerometerInterval / 1000
28 | motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { (data, error) -> Void in
29 | let dic = NSMutableDictionary()
30 | dic["x"] = data!.acceleration.x * self.kGravitationalConstant
31 | dic["y"] = data!.acceleration.y * self.kGravitationalConstant
32 | dic["z"] = data!.acceleration.z * self.kGravitationalConstant
33 | dic["timestamp"] = NSDate().timeIntervalSince1970
34 | if self.callback(dic) {
35 | self.motionManager.stopAccelerometerUpdates()
36 | }
37 | })
38 | if !self.isRunning {
39 | self.isRunning = true
40 | }
41 | } else {
42 | self.errorCallback("accelerometer not available!")
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // BuildYourOwnHybridDevelopmentFramework
4 | //
5 | // Created by 吕文翰 on 15/9/1.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/Console.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Console.swift
3 | // BuildYourOwnHybridDevelopmentFramework
4 | //
5 | // Created by 吕文翰 on 15/9/3.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | class Console: Plugin {
12 | func log() {
13 | if let string = self.data {
14 | NSLog("OOXX >>> " + string)
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSAppTransportSecurity
6 |
7 | NSAllowsArbitraryLoads
8 |
9 |
10 | CFBundleDevelopmentRegion
11 | en
12 | CFBundleExecutable
13 | $(EXECUTABLE_NAME)
14 | CFBundleIdentifier
15 | $(PRODUCT_BUNDLE_IDENTIFIER)
16 | CFBundleInfoDictionaryVersion
17 | 6.0
18 | CFBundleName
19 | $(PRODUCT_NAME)
20 | CFBundlePackageType
21 | APPL
22 | CFBundleShortVersionString
23 | 1.0
24 | CFBundleSignature
25 | ????
26 | CFBundleVersion
27 | 1
28 | LSRequiresIPhoneOS
29 |
30 | UILaunchStoryboardName
31 | LaunchScreen
32 | UIMainStoryboardFile
33 | Main
34 | UIRequiredDeviceCapabilities
35 |
36 | armv7
37 |
38 | UISupportedInterfaceOrientations
39 |
40 | UIInterfaceOrientationPortrait
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | UISupportedInterfaceOrientations~ipad
45 |
46 | UIInterfaceOrientationPortrait
47 | UIInterfaceOrientationPortraitUpsideDown
48 | UIInterfaceOrientationLandscapeLeft
49 | UIInterfaceOrientationLandscapeRight
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // BuildYourOwnHybridDevelopmentFramework
4 | //
5 | // Created by 吕文翰 on 15/9/1.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import WebKit
11 |
12 | class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate, WKScriptMessageHandler {
13 |
14 | var wk: WKWebView!
15 |
16 | override func viewDidLoad() {
17 | super.viewDidLoad()
18 | }
19 |
20 | override func didReceiveMemoryWarning() {
21 | super.didReceiveMemoryWarning()
22 | // Dispose of any resources that can be recreated.
23 | }
24 |
25 | override func viewDidAppear(animated: Bool) {
26 | super.viewDidAppear(animated)
27 |
28 | // 初始化代码放在此处 viewDidAppear 中只是一种为了方便演示的妥协方案,不适用于生产环境。
29 | // 如果需要应用在生产环境中,请参考:https://github.com/Lucky-Orange/BlackHawk
30 | let conf = WKWebViewConfiguration()
31 | conf.userContentController.addScriptMessageHandler(self, name: "OOXX")
32 |
33 | self.wk = WKWebView(frame: self.view.frame, configuration: conf)
34 | self.wk.navigationDelegate = self
35 | self.wk.UIDelegate = self
36 | self.wk.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.baidu.com/")!))
37 |
38 | self.runPluginJS(["Base", "Console", "Accelerometer"])
39 |
40 | self.view.addSubview(self.wk)
41 | }
42 |
43 | func runPluginJS(names: Array) {
44 | for name in names {
45 | if let path = NSBundle.mainBundle().pathForResource(name, ofType: "js", inDirectory: "www/plugins") {
46 | do {
47 | let js = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding)
48 | self.wk.evaluateJavaScript(js as String, completionHandler: nil)
49 | } catch let error as NSError {
50 | NSLog(error.debugDescription)
51 | }
52 | }
53 | }
54 | }
55 |
56 | }
57 |
58 | private typealias wkNavigationDelegate = ViewController
59 | extension wkNavigationDelegate {
60 |
61 | func webView(webView: WKWebView, didFailNavigation navigation: WKNavigation!, withError error: NSError) {
62 | NSLog(error.debugDescription)
63 | }
64 | func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
65 | NSLog(error.debugDescription)
66 | }
67 | }
68 |
69 | private typealias wkUIDelegate = ViewController
70 | extension wkUIDelegate {
71 |
72 | func webView(webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: () -> Void) {
73 | let ac = UIAlertController(title: webView.title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
74 | ac.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: { (aa) -> Void in
75 | completionHandler()
76 | }))
77 | self.presentViewController(ac, animated: true, completion: nil)
78 | }
79 | }
80 |
81 | private typealias wkScriptMessageHandler = ViewController
82 | extension wkScriptMessageHandler {
83 |
84 | func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
85 | if message.name == "OOXX" {
86 | if let dic = message.body as? NSDictionary,
87 | className = dic["className"]?.description,
88 | functionName = dic["functionName"]?.description {
89 | if let cls = NSClassFromString(NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName")!.description + "." + className) as? Plugin.Type{
90 | let obj = cls.init()
91 | obj.wk = self.wk
92 | obj.taskId = dic["taskId"]?.integerValue
93 | obj.data = dic["data"]?.description
94 | let functionSelector = Selector(functionName)
95 | if obj.respondsToSelector(functionSelector) {
96 | obj.performSelector(functionSelector)
97 | } else {
98 | print("方法未找到!")
99 | }
100 | } else {
101 | print("类未找到!")
102 | }
103 | }
104 | }
105 | }
106 | }
107 |
108 | class Plugin: NSObject {
109 | var wk: WKWebView!
110 | var taskId: Int!
111 | var data: String?
112 | required override init() {
113 | }
114 | func callback(values: NSDictionary) -> Bool {
115 | do {
116 | let jsonData = try NSJSONSerialization.dataWithJSONObject(values, options: NSJSONWritingOptions())
117 | if let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding) as? String {
118 | let js = "fireTask(\(self.taskId), '\(jsonString)');"
119 | self.wk.evaluateJavaScript(js, completionHandler: nil)
120 | return true
121 | }
122 | } catch let error as NSError{
123 | NSLog(error.debugDescription)
124 | return false
125 | }
126 | return false
127 | }
128 | func errorCallback(errorMessage: String) {
129 | let js = "onError(\(self.taskId), '\(errorMessage)');"
130 | self.wk.evaluateJavaScript(js, completionHandler: nil)
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFrameworkTests/BuildYourOwnHybridDevelopmentFrameworkTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // BuildYourOwnHybridDevelopmentFrameworkTests.swift
3 | // BuildYourOwnHybridDevelopmentFrameworkTests
4 | //
5 | // Created by 吕文翰 on 15/9/1.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import XCTest
10 | @testable import BuildYourOwnHybridDevelopmentFramework
11 |
12 | class BuildYourOwnHybridDevelopmentFrameworkTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | // Use XCTAssert and related functions to verify your tests produce the correct results.
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFrameworkTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/www/plugins/Accelerometer.js:
--------------------------------------------------------------------------------
1 | navigator.accelerometer = {
2 | getCurrentAcceleration: function(onSuccess, onError) {
3 | Queue.push(Task.init(Queue.length, onSuccess, onError));
4 | window.webkit.messageHandlers.OOXX.postMessage({className: 'Accelerometer', functionName: 'getCurrentAcceleration', taskId: Queue.length - 1});
5 | }
6 | }
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/www/plugins/Base.js:
--------------------------------------------------------------------------------
1 | Queue = [];
2 | Task = {
3 | id: 0,
4 | callback: function(){},
5 | errorCallback: function(){},
6 | init: function(id, callback, errorCallback) {
7 | this.id = id;
8 | this.callback = callback;
9 | this.errorCallback = errorCallback;
10 | return this
11 | }
12 | };
13 | fireTask = function(i, j) {
14 | Queue[i].callback(JSON.parse(j));
15 | };
16 | onError = function (i, j) {
17 | Queue[i].errorCallback(j);
18 | };
--------------------------------------------------------------------------------
/BuildYourOwnHybridDevelopmentFramework/www/plugins/Console.js:
--------------------------------------------------------------------------------
1 | console = {
2 | log: function (string) {
3 | window.webkit.messageHandlers.OOXX.postMessage({className: 'Console', functionName: 'log', data: string});
4 | }
5 | }
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace/xcshareddata/ControlOrientation.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | 5D1D31F4-9DE7-4275-A81C-A7C6CEE4DD8B
9 | IDESourceControlProjectName
10 | project
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
14 | github.com:johnlui/Swift-On-iOS.git
15 |
16 | IDESourceControlProjectPath
17 | ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
21 | ../../..
22 |
23 | IDESourceControlProjectURL
24 | github.com:johnlui/Swift-On-iOS.git
25 | IDESourceControlProjectVersion
26 | 111
27 | IDESourceControlProjectWCCIdentifier
28 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
36 | IDESourceControlWCCName
37 | Swift%20On%20iOS
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/ControlOrientation/ControlOrientation.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/ControlOrientation.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ControlOrientation.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 460573EA1B6BCF970056BDD0
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/ControlOrientation.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ControlOrientation.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 460573EA1B6BCF970056BDD0
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // ControlOrientation
4 | //
5 | // Created by JohnLui on 15/7/31.
6 | // Copyright © 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/NavigationController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NavigationController.swift
3 | // ControlOrientation
4 | //
5 | // Created by JohnLui on 15/8/1.
6 | // Copyright © 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class NavigationController: UINavigationController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 |
16 | // Do any additional setup after loading the view.
17 | }
18 |
19 | override func didReceiveMemoryWarning() {
20 | super.didReceiveMemoryWarning()
21 | // Dispose of any resources that can be recreated.
22 | }
23 |
24 | override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
25 | return self.visibleViewController!.supportedInterfaceOrientations()
26 | }
27 | override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
28 | return self.visibleViewController!.preferredInterfaceOrientationForPresentation()
29 | }
30 | /*
31 | // MARK: - Navigation
32 |
33 | // In a storyboard-based application, you will often want to do a little preparation before navigation
34 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
35 | // Get the new view controller using segue.destinationViewController.
36 | // Pass the selected object to the new view controller.
37 | }
38 | */
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/SecondViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SecondViewController.swift
3 | // ControlOrientation
4 | //
5 | // Created by JohnLui on 15/7/31.
6 | // Copyright © 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | enum ScreenOrientation {
12 | case Heng, Shu
13 | }
14 |
15 | class SecondViewController: UIViewController {
16 |
17 | var orientation = ScreenOrientation.Shu
18 |
19 | override func viewDidLoad() {
20 | super.viewDidLoad()
21 |
22 | if self.orientation == ScreenOrientation.Heng {
23 | UIDevice.currentDevice().setValue(UIInterfaceOrientation.LandscapeLeft.rawValue, forKey: "orientation")
24 | }
25 | }
26 |
27 | override func didReceiveMemoryWarning() {
28 | super.didReceiveMemoryWarning()
29 | // Dispose of any resources that can be recreated.
30 | }
31 |
32 | @IBAction func dismissSelfVC(sender: AnyObject) {
33 | self.dismissViewControllerAnimated(true, completion: nil)
34 | }
35 |
36 | override func shouldAutorotate() -> Bool {
37 | return false
38 | }
39 |
40 | override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
41 | return self.orientation == ScreenOrientation.Shu ? UIInterfaceOrientationMask.Portrait : UIInterfaceOrientationMask.All
42 | }
43 | override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
44 | return self.orientation == ScreenOrientation.Shu ? UIInterfaceOrientation.Portrait : UIInterfaceOrientation.LandscapeLeft
45 | }
46 | /*
47 | // MARK: - Navigation
48 |
49 | // In a storyboard-based application, you will often want to do a little preparation before navigation
50 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
51 | // Get the new view controller using segue.destinationViewController.
52 | // Pass the selected object to the new view controller.
53 | }
54 | */
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/TabBarController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TabBarController.swift
3 | // ControlOrientation
4 | //
5 | // Created by JohnLui on 15/8/1.
6 | // Copyright © 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class TabBarController: UITabBarController, UITabBarControllerDelegate {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | self.delegate = self
16 | }
17 |
18 | override func didReceiveMemoryWarning() {
19 | super.didReceiveMemoryWarning()
20 | }
21 |
22 | override func shouldAutorotate() -> Bool {
23 | return false
24 | }
25 | func tabBarControllerSupportedInterfaceOrientations(tabBarController: UITabBarController) -> UIInterfaceOrientationMask {
26 | return self.selectedViewController!.supportedInterfaceOrientations()
27 | }
28 | func tabBarControllerPreferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
29 | return self.selectedViewController!.preferredInterfaceOrientationForPresentation()
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ControlOrientation/ControlOrientation/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // ControlOrientation
4 | //
5 | // Created by JohnLui on 15/7/31.
6 | // Copyright © 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | // Do any additional setup after loading the view, typically from a nib.
16 | }
17 |
18 | override func didReceiveMemoryWarning() {
19 | super.didReceiveMemoryWarning()
20 | // Dispose of any resources that can be recreated.
21 | }
22 |
23 | @IBAction func openNewVC(sender: AnyObject) {
24 | if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("secondVC") as? SecondViewController {
25 | vc.orientation = ScreenOrientation.Heng
26 | self.presentViewController(vc, animated: true, completion: nil)
27 | }
28 | }
29 |
30 | override func shouldAutorotate() -> Bool {
31 | return false
32 | }
33 |
34 | override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
35 | return UIInterfaceOrientationMask.Portrait
36 | }
37 | override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
38 | return UIInterfaceOrientation.Portrait
39 | }
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/project.xcworkspace/xcshareddata/DifferentWaysToBuildTheUserInterface.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | 4F6E68CC-0393-4198-8834-AB649E26DCBA
9 | IDESourceControlProjectName
10 | DifferentWaysToBuildTheUserInterface
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
14 | github.com:johnlui/Swift-On-iOS.git
15 |
16 | IDESourceControlProjectPath
17 | DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
21 | ../../..
22 |
23 | IDESourceControlProjectURL
24 | github.com:johnlui/Swift-On-iOS.git
25 | IDESourceControlProjectVersion
26 | 111
27 | IDESourceControlProjectWCCIdentifier
28 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | 03AD7DF3D7364946A0586E0BE3EE422D655B389D
36 | IDESourceControlWCCName
37 | Swift%20On%20iOS
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/DifferentWaysToBuildTheUserInterface.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | DifferentWaysToBuildTheUserInterface.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 468268501AFCDC1700CC0A62
16 |
17 | primary
18 |
19 |
20 | 468268651AFCDC1700CC0A62
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/DifferentWaysToBuildTheUserInterface.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
75 |
77 |
83 |
84 |
85 |
86 |
87 |
88 |
94 |
96 |
102 |
103 |
104 |
105 |
107 |
108 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | DifferentWaysToBuildTheUserInterface.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 468268501AFCDC1700CC0A62
16 |
17 | primary
18 |
19 |
20 | 468268651AFCDC1700CC0A62
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // DifferentWaysToBuildTheUserInterface
4 | //
5 | // Created by JohnLui on 15/5/8.
6 | // Copyright (c) 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Button.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Images.xcassets/80.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "scale" : "2x",
10 | "filename" : "gold@2x.png"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Images.xcassets/80.imageset/gold@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Images.xcassets/80.imageset/gold@2x.png
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/Second.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // DifferentWaysToBuildTheUserInterface
4 | //
5 | // Created by JohnLui on 15/5/8.
6 | // Copyright (c) 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 |
16 | let button = NSBundle.mainBundle().loadNibNamed("Button", owner: self, options: nil).first as! UIButton
17 | button.center = self.view.center
18 | self.view.addSubview(button)
19 | }
20 |
21 | override func didReceiveMemoryWarning() {
22 | super.didReceiveMemoryWarning()
23 | // Dispose of any resources that can be recreated.
24 | }
25 |
26 | @IBAction func gotoSecondStoryboardButtonBeTapped(sender: AnyObject) {
27 | let vc = UIStoryboard(name: "Second", bundle: nil)
28 | .instantiateViewControllerWithIdentifier("First")
29 | self.navigationController?.pushViewController(vc, animated: true)
30 | // self.presentViewController(vc, animated: true, completion: nil)
31 | }
32 |
33 | @IBAction func centerButtonBeTapped(sender: AnyObject) {
34 | print("centerButtonBeTapped")
35 | }
36 |
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterfaceTests/DifferentWaysToBuildTheUserInterfaceTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DifferentWaysToBuildTheUserInterfaceTests.swift
3 | // DifferentWaysToBuildTheUserInterfaceTests
4 | //
5 | // Created by JohnLui on 15/5/8.
6 | // Copyright (c) 2015年 http://lvwenhan.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import XCTest
11 |
12 | class DifferentWaysToBuildTheUserInterfaceTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | XCTAssert(true, "Pass")
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock() {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterfaceTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/EasyFormValidator/EasyFormValidator.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/EasyFormValidator/EasyFormValidator.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/EasyFormValidator.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | EasyFormValidator.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 46EC34871B71255F00A407DC
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/EasyFormValidator.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | EasyFormValidator.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 46EC34871B71255F00A407DC
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // EasyFormValidator
4 | //
5 | // Created by JohnLui on 15/8/5.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/EasyFormValidator/EasyFormValidator/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // EasyFormValidator
4 | //
5 | // Created by JohnLui on 15/8/5.
6 | // Copyright © 2015年 JohnLui. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | extension UIButton {
12 | func disable() {
13 | self.enabled = false
14 | self.alpha = 0.5
15 | }
16 | func enable() {
17 | self.enabled = true
18 | self.alpha = 1
19 | }
20 | }
21 |
22 | extension UITextField {
23 | var notEmpty: Bool{
24 | get {
25 | return self.text != ""
26 | }
27 | }
28 | func validate(RegEx: String) -> Bool {
29 | let predicate = NSPredicate(format: "SELF MATCHES %@", RegEx)
30 | return predicate.evaluateWithObject(self.text)
31 | }
32 | func validateEmail() -> Bool {
33 | return self.validate("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}")
34 | }
35 | func validatePhoneNumber() -> Bool {
36 | return self.validate("^\\d{11}$")
37 | }
38 | func validatePassword() -> Bool {
39 | return self.validate("^[A-Z0-9a-z]{6,18}")
40 | }
41 | }
42 |
43 | class ViewController: UIViewController {
44 |
45 | @IBOutlet weak var emailTextField: UITextField!
46 | @IBOutlet weak var phoneNumberTextField: UITextField!
47 | @IBOutlet weak var passwordTextField: UITextField!
48 | @IBOutlet weak var loginButton: UIButton!
49 | override func viewDidLoad() {
50 | super.viewDidLoad()
51 |
52 | self.loginButton.disable()
53 | }
54 |
55 | override func didReceiveMemoryWarning() {
56 | super.didReceiveMemoryWarning()
57 | // Dispose of any resources that can be recreated.
58 | }
59 |
60 | @IBAction func editingChanged(sender: AnyObject) {
61 | if self.emailTextField.notEmpty && self.phoneNumberTextField.notEmpty && self.passwordTextField.notEmpty {
62 | self.loginButton.enable()
63 | } else {
64 | self.loginButton.disable()
65 | }
66 | }
67 | @IBAction func loginButtonBeTapped(sender: AnyObject) {
68 | if self.emailTextField.validateEmail() {
69 | if self.phoneNumberTextField.validatePhoneNumber() {
70 | if self.passwordTextField.validatePassword() {
71 | self.alert("验证成功!")
72 | } else {
73 | self.alert("密码格式不合法")
74 | }
75 | } else {
76 | self.alert("手机号格式不合法")
77 | }
78 | } else {
79 | self.alert("邮箱格式不合法")
80 | }
81 | }
82 |
83 | func alert(message: String) {
84 | let alc = UIAlertController(title: message, message: nil, preferredStyle: UIAlertControllerStyle.Alert)
85 | alc.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Cancel, handler: nil))
86 | self.presentViewController(alc, animated: true, completion: nil)
87 | }
88 |
89 | }
90 |
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | JohnLui 的 Swift On iOS 代码仓库
2 | --
3 |
4 | iOS 开发知识大多为点状分布,比较难成体系。本 repo 将保存我的那些无法成系列文章的示例代码,给她们一个温暖的家。
5 |
6 | ### 环境: Xcode 7 / Swift 2.0
7 |
8 | ## 文章列表
9 |
10 | ### 一、iOS 开发 UI 搭建心得
11 |
12 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/blob/master/DifferentWaysToBuildTheUserInterface/DifferentWaysToBuildTheUserInterface)
13 |
14 | > #### 1. [iOS 开发 UI 搭建心得(一)—— 驾驭 StoryBoard](http://lvwenhan.com/ios/452.html)
15 | > #### 2. [iOS 开发 UI 搭建心得(二)—— 善用 xib](http://lvwenhan.com/ios/453.html)
16 |
17 | ### 二、自己动手写一个 iOS 网络请求库
18 |
19 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/blob/master/BuildYourHTTPRequestLibrary/BuildYourHTTPRequestLibrary)
20 |
21 | > #### 1. [自己动手写一个 iOS 网络请求库(一)—— NSURLSession 初探](http://lvwenhan.com/ios/454.html)
22 | > #### 2. [自己动手写一个 iOS 网络请求库(二)——封装接口](http://lvwenhan.com/ios/455.html)
23 | > #### 3. [自己动手写一个 iOS 网络请求库(三)——降低耦合](http://lvwenhan.com/ios/456.html)
24 | > #### 4. [自己动手写一个 iOS 网络请求库(四)——快速文件上传](http://lvwenhan.com/ios/457.html)
25 | > #### 5. [自己动手写一个 iOS 网络请求库(五)——设置 SSL 钢钉](http://lvwenhan.com/ios/464.html)
26 |
27 | ### 三、基于 XML 配置的完全可插拔的 js 向 Swift 的反射
28 |
29 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/blob/master/TestReflection/TestReflection)
30 |
31 | WKWebView 惨无人道,一句话完成 js 向 native 层传值,逼死 Cordova 的节奏。
32 |
33 | ### 四、如何用代码控制以不同屏幕方向打开新页面
34 |
35 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/tree/master/ControlOrientation/ControlOrientation)
36 |
37 | > #### [如何用代码控制以不同屏幕方向打开新页面](http://lvwenhan.com/ios/458.html)
38 |
39 |
40 | ### 五、自己动手构建表单验证功能
41 |
42 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/tree/master/EasyFormValidator/EasyFormValidator)
43 |
44 | > #### [自己动手构建表单验证功能【iOS】](http://lvwenhan.com/ios/459.html)
45 |
46 |
47 | ### 六、自己动手打造基于 WKWebView 的混合开发框架
48 |
49 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/tree/master/BuildYourOwnHybridDevelopmentFramework/BuildYourOwnHybridDevelopmentFramework)
50 |
51 | > #### 1. [自己动手打造基于 WKWebView 的混合开发框架(一)——WKWebView 上手](http://lvwenhan.com/ios/460.html)
52 | > #### 2. [自己动手打造基于 WKWebView 的混合开发框架(二)——js 向 Native 一句话传值并反射出 Swift 对象执行指定函数](http://lvwenhan.com/ios/461.html)
53 | > #### 3. [自己动手打造基于 WKWebView 的混合开发框架(三)——设计插件协议以兼容 Cordova](http://lvwenhan.com/ios/462.html)
54 |
55 |
56 |
57 | ### 七、自己动手造无限循环图片轮播
58 |
59 | [点我直达代码](https://github.com/johnlui/Swift-On-iOS/tree/master/InfiniteCarouselScrollView/InfiniteCarouselScrollView)
60 |
61 | > #### [自己动手造无限循环图片轮播](https://autolayout.club/2015/10/29/%E8%87%AA%E5%B7%B1%E5%8A%A8%E6%89%8B%E9%80%A0%E6%97%A0%E9%99%90%E5%BE%AA%E7%8E%AF%E5%9B%BE%E7%89%87%E8%BD%AE%E6%92%AD/)
62 |
63 |
64 | ## License
65 |
66 | 此项目下所有代码均基于 MIT license 开源。
67 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/TestReflection/TestReflection.xcodeproj/project.xcworkspace/xcuserdata/JohnLui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlui/Swift-On-iOS/f6f63ce14ffae4c78eed2852f4ac1462a2e95c44/TestReflection/TestReflection.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/TestReflection.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/xcuserdata/JohnLui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | TestReflection.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 46D853651B21E46B00FDED1B
16 |
17 | primary
18 |
19 |
20 | 46D8537A1B21E46C00FDED1B
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/TestReflection.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
75 |
77 |
83 |
84 |
85 |
86 |
87 |
88 |
94 |
96 |
102 |
103 |
104 |
105 |
107 |
108 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection.xcodeproj/xcuserdata/dren_a.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | TestReflection.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 46D853651B21E46B00FDED1B
16 |
17 | primary
18 |
19 |
20 | 46D8537A1B21E46C00FDED1B
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // TestReflection
4 | //
5 | // Created by JohnLui on 15/6/5.
6 | // Copyright (c) 2015年 http://www.leqicheng.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection/Console.swift:
--------------------------------------------------------------------------------
1 | //
2 | // File.swift
3 | // TestReflection
4 | //
5 | // Created by JohnLui on 15/6/5.
6 | // Copyright (c) 2015年 http://www.leqicheng.com. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | class Console: NSObject {
12 | required init(string: String) {
13 | NSLog(string)
14 | }
15 | }
16 |
17 | class ConsoleClass: Console {
18 | }
19 |
20 | class HaohaowanClass: Console {
21 | }
--------------------------------------------------------------------------------
/TestReflection/TestReflection/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/TestReflection/TestReflection/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.leqicheng.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // TestReflection
4 | //
5 | // Created by JohnLui on 15/6/5.
6 | // Copyright (c) 2015年 http://www.leqicheng.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import WebKit
11 |
12 | struct Plugin {
13 | let name: String!
14 | let className: String!
15 | }
16 |
17 | class ViewController: UIViewController, WKScriptMessageHandler, NSXMLParserDelegate {
18 |
19 | var pluginItemName = ""
20 | var pluginsDictionary = Dictionary()
21 |
22 | var wk: WKWebView!
23 |
24 | override func viewDidLoad() {
25 | super.viewDidLoad()
26 | if let path = NSBundle.mainBundle().pathForResource("plugins", ofType: "xml") {
27 | let url = NSURL(fileURLWithPath: path)
28 | if let xmlParser = NSXMLParser(contentsOfURL: url) {
29 | xmlParser.delegate = self
30 | xmlParser.parse()
31 | }
32 | }
33 | }
34 |
35 | override func didReceiveMemoryWarning() {
36 | super.didReceiveMemoryWarning()
37 | // Dispose of any resources that can be recreated.
38 | }
39 |
40 | override func viewDidAppear(animated: Bool) {
41 | super.viewDidAppear(animated)
42 |
43 | let request = NSURLRequest(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("index", ofType: "html", inDirectory: "www")!))
44 |
45 | let conf = WKWebViewConfiguration()
46 | conf.userContentController.addScriptMessageHandler(self, name: "callbackHandler")
47 |
48 | wk = WKWebView(frame: self.view.frame, configuration: conf)
49 | self.view.addSubview(wk)
50 | wk.loadRequest(request)
51 | }
52 |
53 | func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
54 | if(message.name == "callbackHandler") {
55 | let array = message.body.componentsSeparatedByString("://")
56 | if array.count == 2 {
57 | if let plugin = self.pluginsDictionary[array[0]] {
58 | if let cls = NSClassFromString(NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName")!.description + "." + plugin.className) as? Console.Type{
59 | let obj = cls.init(string: array[1])
60 | }
61 | } else {
62 | NSLog("反射失败!类 \(array[0]) 未找到")
63 | }
64 | } else {
65 | NSLog("反射失败!完整数据:\(message.body)")
66 | }
67 | }
68 | }
69 |
70 | func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
71 | if elementName == "item" {
72 | if let name = attributeDict["name"] {
73 | self.pluginItemName = name
74 | }
75 | } else if self.pluginItemName != "" && elementName == "param" {
76 | let plugin = Plugin(name: self.pluginItemName, className: attributeDict["value"])
77 | self.pluginsDictionary[self.pluginItemName] = plugin
78 | }
79 | }
80 |
81 | }
82 |
83 |
--------------------------------------------------------------------------------
/TestReflection/TestReflection/plugins.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 | -
7 |
8 |
9 |
--------------------------------------------------------------------------------
/TestReflection/TestReflectionTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.leqicheng.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/TestReflection/TestReflectionTests/TestReflectionTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TestReflectionTests.swift
3 | // TestReflectionTests
4 | //
5 | // Created by JohnLui on 15/6/5.
6 | // Copyright (c) 2015年 http://www.leqicheng.com. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import XCTest
11 |
12 | class TestReflectionTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | XCTAssert(true, "Pass")
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock() {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/TestReflection/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SwiftCordovaLib
6 |
7 |
8 |
9 |
10 | SwiftCordovaLib
11 |
12 |
13 |
--------------------------------------------------------------------------------
/TestReflection/www/js/main.js:
--------------------------------------------------------------------------------
1 | $(document).ready( function() {
2 | window.setTimeout(function() {
3 | try {
4 | window.webkit.messageHandlers.callbackHandler.postMessage("Console://fuck");
5 | } catch(err) {
6 | console.log('The native context does not exist yet');
7 | }
8 | }, 500);
9 | });
--------------------------------------------------------------------------------