├── .gitignore ├── Demo ├── Demo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── Balzac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── Balzac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── Demo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── icon-20-ipad.png │ │ ├── icon-20@2x-ipad.png │ │ ├── icon-20@2x.png │ │ ├── icon-20@3x.png │ │ ├── icon-29-ipad.png │ │ ├── icon-29@2x-ipad.png │ │ ├── icon-29@2x.png │ │ ├── icon-29@3x.png │ │ ├── icon-40.png │ │ ├── icon-40@2x-1.png │ │ ├── icon-40@2x.png │ │ ├── icon-40@3x.png │ │ ├── icon-60@2x.png │ │ ├── icon-60@3x.png │ │ ├── icon-76.png │ │ ├── icon-76@2x.png │ │ └── icon-83.5@2x.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── Masonry │ ├── MASCompositeConstraint.h │ ├── MASCompositeConstraint.m │ ├── MASConstraint+Private.h │ ├── MASConstraint.h │ ├── MASConstraint.m │ ├── MASConstraintMaker.h │ ├── MASConstraintMaker.m │ ├── MASLayoutConstraint.h │ ├── MASLayoutConstraint.m │ ├── MASUtilities.h │ ├── MASViewAttribute.h │ ├── MASViewAttribute.m │ ├── MASViewConstraint.h │ ├── MASViewConstraint.m │ ├── Masonry.h │ ├── NSArray+MASAdditions.h │ ├── NSArray+MASAdditions.m │ ├── NSArray+MASShorthandAdditions.h │ ├── NSLayoutConstraint+MASDebugAdditions.h │ ├── NSLayoutConstraint+MASDebugAdditions.m │ ├── View+MASAdditions.h │ ├── View+MASAdditions.m │ ├── View+MASShorthandAdditions.h │ ├── ViewController+MASAdditions.h │ └── ViewController+MASAdditions.m │ ├── PrefixHeader.pch │ ├── ViewController.h │ ├── ViewController.m │ ├── bgStory.jpg │ └── main.m ├── README.md ├── ReadmeResource ├── introduce.png ├── license.png ├── platform.png ├── screenshot.jpg ├── show.gif └── support.png └── WHStoryMaker ├── Resource └── StoryMaker.xcassets │ ├── Contents.json │ ├── story_maker_close.imageset │ ├── Contents.json │ ├── story maker_close@2x.png │ └── story maker_close@3x.png │ ├── story_maker_fontborder.imageset │ ├── Contents.json │ ├── story maker_fontborder@2x.png │ └── story maker_fontborder@3x.png │ ├── story_maker_fontsize.imageset │ ├── Contents.json │ ├── story maker_fontsize@2x.png │ └── story maker_fontsize@3x.png │ ├── story_maker_next.imageset │ ├── Contents.json │ ├── story maker_next@2x.png │ └── story maker_next@3x.png │ ├── story_maker_tab_filter.imageset │ ├── Contents.json │ ├── story maker_tab_filter@2x.png │ └── story maker_tab_filter@3x.png │ ├── story_maker_tab_scrawl.imageset │ ├── Contents.json │ ├── story maker_tab_scrawl@2x.png │ └── story maker_tab_scrawl@3x.png │ ├── story_maker_tab_sticker.imageset │ ├── Contents.json │ ├── story maker_tab_sticker@2x.png │ └── story maker_tab_sticker@3x.png │ ├── story_maker_tab_type.imageset │ ├── Contents.json │ ├── story maker_tab_type@2x.png │ └── story maker_tab_type@3x.png │ ├── story_maker_tiezhi0.imageset │ ├── Contents.json │ └── img.png │ ├── story_maker_tiezhi1.imageset │ ├── Contents.json │ └── img.png │ ├── story_maker_tiezhi2.imageset │ ├── Contents.json │ └── img.png │ ├── story_maker_tiezhi3.imageset │ ├── Contents.json │ └── img.png │ └── story_maker_tiezhi4.imageset │ ├── Contents.json │ └── img.png ├── StoryMakerEditor ├── StoryMakeImageEditorViewController.h ├── StoryMakeImageEditorViewController.m └── View │ ├── Draw │ ├── LSDrawView.h │ ├── LSDrawView.m │ └── YYModel │ │ ├── LJBaseModel.h │ │ ├── LJBaseModel.m │ │ ├── NSObject+YYModel.h │ │ ├── NSObject+YYModel.m │ │ ├── YYClassInfo.h │ │ ├── YYClassInfo.m │ │ └── YYModel.h │ ├── Filter │ ├── Helper │ │ ├── ColorMatrix.h │ │ ├── ImageUtil.h │ │ └── ImageUtil.m │ ├── StoryMakeFilterFooterView.h │ ├── StoryMakeFilterFooterView.m │ ├── StoryMakeFooterFilterCell.h │ └── StoryMakeFooterFilterCell.m │ ├── Sticker │ ├── StoryMakeStickerBaseView.h │ ├── StoryMakeStickerBaseView.m │ ├── StoryMakeStickerFootSingleViewController.h │ ├── StoryMakeStickerFootSingleViewController.m │ ├── StoryMakeStickerFooterCell.h │ ├── StoryMakeStickerFooterCell.m │ ├── StoryMakeStickerImageView.h │ ├── StoryMakeStickerImageView.m │ ├── StoryMakeStickerView.h │ └── StoryMakeStickerView.m │ ├── StoryMakeToolsView.h │ ├── StoryMakeToolsView.m │ └── Write │ ├── StoryMakeSelectColorFooterView.h │ ├── StoryMakeSelectColorFooterView.m │ ├── StoryMakeStickerColorFootCollectionViewCell.h │ ├── StoryMakeStickerColorFootCollectionViewCell.m │ ├── StoryMakeStickerColorFootSingleViewController.h │ ├── StoryMakeStickerColorFootSingleViewController.m │ ├── StoryMakeStickerLabelView.h │ └── StoryMakeStickerLabelView.m ├── StoryMakerHelper ├── CDPMonitorKeyboard.h ├── CDPMonitorKeyboard.m ├── StoryMakerFontManager.h ├── StoryMakerFontManager.m ├── UIImage+imageWithColor.h └── UIImage+imageWithColor.m └── WHStoryMakerHeader.h /.gitignore: -------------------------------------------------------------------------------- 1 | .orig 2 | .vscode/ 3 | Pods/ 4 | Podfile.lock 5 | .xcscheme 6 | 7 | *.DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | 15 | # Thumbnails 16 | ._* 17 | 18 | # Files that might appear in the root of a volume 19 | .DocumentRevisions-V100 20 | .fseventsd 21 | .Spotlight-V100 22 | .TemporaryItems 23 | .Trashes 24 | .VolumeIcon.icns 25 | .com.apple.timemachine.donotpresent 26 | 27 | # Directories potentially created on remote AFP share 28 | .AppleDB 29 | .AppleDesktop 30 | Network Trash Folder 31 | Temporary Items 32 | .apdisk 33 | 34 | # Xcode 35 | # 36 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 37 | 38 | ## Build generated 39 | build/ 40 | DerivedData/ 41 | 42 | ## Various settings 43 | *.pbxuser 44 | !default.pbxuser 45 | *.mode1v3 46 | !default.mode1v3 47 | *.mode2v3 48 | !default.mode2v3 49 | *.perspectivev3 50 | !default.perspectivev3 51 | xcuserdata/ 52 | 53 | ## Other 54 | *.moved-aside 55 | *.xcuserstate 56 | 57 | ## Obj-C/Swift specific 58 | *.hmap 59 | *.ipa 60 | *.dSYM.zip 61 | *.dSYM 62 | 63 | # CocoaPods 64 | # 65 | # We recommend against adding the Pods directory to your .gitignore. However 66 | # you should judge for yourself, the pros and cons are mentioned at: 67 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 68 | # 69 | # Pods/ 70 | 71 | # Carthage 72 | # 73 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 74 | # Carthage/Checkouts 75 | 76 | Carthage/Build 77 | 78 | # fastlane 79 | # 80 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 81 | # screenshots whenever they are needed. 82 | # For more information about the recommended setup visit: 83 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 84 | 85 | fastlane/report.xml 86 | fastlane/screenshots 87 | 88 | # Code Injection 89 | # 90 | # After new code Injection tools there's a generated folder /iOSInjectionProject 91 | # https://github.com/johnno1962/injectionforxcode 92 | 93 | iOSInjectionProject/ 94 | 95 | */xcuserdata/ 96 | *.orig 97 | *.xcworkspace/ -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/project.xcworkspace/xcuserdata/Balzac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo.xcodeproj/project.xcworkspace/xcuserdata/Balzac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/xcuserdata/Balzac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/xcuserdata/Balzac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Demo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Demo/Demo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Demo/Demo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "icon-20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "icon-20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "icon-29@2x.png", 19 | "scale" : "2x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "icon-29@3x.png", 25 | "scale" : "3x" 26 | }, 27 | { 28 | "size" : "40x40", 29 | "idiom" : "iphone", 30 | "filename" : "icon-40@2x.png", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "icon-40@3x.png", 37 | "scale" : "3x" 38 | }, 39 | { 40 | "size" : "60x60", 41 | "idiom" : "iphone", 42 | "filename" : "icon-60@2x.png", 43 | "scale" : "2x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "icon-60@3x.png", 49 | "scale" : "3x" 50 | }, 51 | { 52 | "size" : "20x20", 53 | "idiom" : "ipad", 54 | "filename" : "icon-20-ipad.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "icon-20@2x-ipad.png", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "size" : "29x29", 65 | "idiom" : "ipad", 66 | "filename" : "icon-29-ipad.png", 67 | "scale" : "1x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "icon-29@2x-ipad.png", 73 | "scale" : "2x" 74 | }, 75 | { 76 | "size" : "40x40", 77 | "idiom" : "ipad", 78 | "filename" : "icon-40.png", 79 | "scale" : "1x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "icon-40@2x-1.png", 85 | "scale" : "2x" 86 | }, 87 | { 88 | "size" : "76x76", 89 | "idiom" : "ipad", 90 | "filename" : "icon-76.png", 91 | "scale" : "1x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "icon-76@2x.png", 97 | "scale" : "2x" 98 | }, 99 | { 100 | "size" : "83.5x83.5", 101 | "idiom" : "ipad", 102 | "filename" : "icon-83.5@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "idiom" : "ios-marketing", 107 | "size" : "1024x1024", 108 | "scale" : "1x" 109 | } 110 | ], 111 | "info" : { 112 | "version" : 1, 113 | "author" : "xcode" 114 | } 115 | } -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20-ipad.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20@2x-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20@2x-ipad.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20@2x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-20@3x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29-ipad.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29@2x-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29@2x-ipad.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40@2x-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40@2x-1.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-76.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png -------------------------------------------------------------------------------- /Demo/Demo/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 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Demo/Demo/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 | -------------------------------------------------------------------------------- /Demo/Demo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | WHStoryMaker 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSPhotoLibraryAddUsageDescription 26 | Allow us to access your photo album. 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | UIViewControllerBasedStatusBarAppearance 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASCompositeConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | /** 13 | * A group of MASConstraint objects 14 | */ 15 | @interface MASCompositeConstraint : MASConstraint 16 | 17 | /** 18 | * Creates a composite with a predefined array of children 19 | * 20 | * @param children child MASConstraints 21 | * 22 | * @return a composite constraint 23 | */ 24 | - (id)initWithChildren:(NSArray *)children; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASCompositeConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASCompositeConstraint.h" 10 | #import "MASConstraint+Private.h" 11 | 12 | @interface MASCompositeConstraint () 13 | 14 | @property (nonatomic, strong) id mas_key; 15 | @property (nonatomic, strong) NSMutableArray *childConstraints; 16 | 17 | @end 18 | 19 | @implementation MASCompositeConstraint 20 | 21 | - (id)initWithChildren:(NSArray *)children { 22 | self = [super init]; 23 | if (!self) return nil; 24 | 25 | _childConstraints = [children mutableCopy]; 26 | for (MASConstraint *constraint in _childConstraints) { 27 | constraint.delegate = self; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | #pragma mark - MASConstraintDelegate 34 | 35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 36 | NSUInteger index = [self.childConstraints indexOfObject:constraint]; 37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint]; 39 | } 40 | 41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 42 | id strongDelegate = self.delegate; 43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 44 | newConstraint.delegate = self; 45 | [self.childConstraints addObject:newConstraint]; 46 | return newConstraint; 47 | } 48 | 49 | #pragma mark - NSLayoutConstraint multiplier proxies 50 | 51 | - (MASConstraint * (^)(CGFloat))multipliedBy { 52 | return ^id(CGFloat multiplier) { 53 | for (MASConstraint *constraint in self.childConstraints) { 54 | constraint.multipliedBy(multiplier); 55 | } 56 | return self; 57 | }; 58 | } 59 | 60 | - (MASConstraint * (^)(CGFloat))dividedBy { 61 | return ^id(CGFloat divider) { 62 | for (MASConstraint *constraint in self.childConstraints) { 63 | constraint.dividedBy(divider); 64 | } 65 | return self; 66 | }; 67 | } 68 | 69 | #pragma mark - MASLayoutPriority proxy 70 | 71 | - (MASConstraint * (^)(MASLayoutPriority))priority { 72 | return ^id(MASLayoutPriority priority) { 73 | for (MASConstraint *constraint in self.childConstraints) { 74 | constraint.priority(priority); 75 | } 76 | return self; 77 | }; 78 | } 79 | 80 | #pragma mark - NSLayoutRelation proxy 81 | 82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { 83 | return ^id(id attr, NSLayoutRelation relation) { 84 | for (MASConstraint *constraint in self.childConstraints.copy) { 85 | constraint.equalToWithRelation(attr, relation); 86 | } 87 | return self; 88 | }; 89 | } 90 | 91 | #pragma mark - attribute chaining 92 | 93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 95 | return self; 96 | } 97 | 98 | #pragma mark - Animator proxy 99 | 100 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 101 | 102 | - (MASConstraint *)animator { 103 | for (MASConstraint *constraint in self.childConstraints) { 104 | [constraint animator]; 105 | } 106 | return self; 107 | } 108 | 109 | #endif 110 | 111 | #pragma mark - debug helpers 112 | 113 | - (MASConstraint * (^)(id))key { 114 | return ^id(id key) { 115 | self.mas_key = key; 116 | int i = 0; 117 | for (MASConstraint *constraint in self.childConstraints) { 118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]); 119 | } 120 | return self; 121 | }; 122 | } 123 | 124 | #pragma mark - NSLayoutConstraint constant setters 125 | 126 | - (void)setInsets:(MASEdgeInsets)insets { 127 | for (MASConstraint *constraint in self.childConstraints) { 128 | constraint.insets = insets; 129 | } 130 | } 131 | 132 | - (void)setOffset:(CGFloat)offset { 133 | for (MASConstraint *constraint in self.childConstraints) { 134 | constraint.offset = offset; 135 | } 136 | } 137 | 138 | - (void)setSizeOffset:(CGSize)sizeOffset { 139 | for (MASConstraint *constraint in self.childConstraints) { 140 | constraint.sizeOffset = sizeOffset; 141 | } 142 | } 143 | 144 | - (void)setCenterOffset:(CGPoint)centerOffset { 145 | for (MASConstraint *constraint in self.childConstraints) { 146 | constraint.centerOffset = centerOffset; 147 | } 148 | } 149 | 150 | #pragma mark - MASConstraint 151 | 152 | - (void)activate { 153 | for (MASConstraint *constraint in self.childConstraints) { 154 | [constraint activate]; 155 | } 156 | } 157 | 158 | - (void)deactivate { 159 | for (MASConstraint *constraint in self.childConstraints) { 160 | [constraint deactivate]; 161 | } 162 | } 163 | 164 | - (void)install { 165 | for (MASConstraint *constraint in self.childConstraints) { 166 | constraint.updateExisting = self.updateExisting; 167 | [constraint install]; 168 | } 169 | } 170 | 171 | - (void)uninstall { 172 | for (MASConstraint *constraint in self.childConstraints) { 173 | [constraint uninstall]; 174 | } 175 | } 176 | 177 | @end 178 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASConstraint+Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint+Private.h 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 29/04/14. 6 | // Copyright (c) 2014 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | 11 | @protocol MASConstraintDelegate; 12 | 13 | 14 | @interface MASConstraint () 15 | 16 | /** 17 | * Whether or not to check for an existing constraint instead of adding constraint 18 | */ 19 | @property (nonatomic, assign) BOOL updateExisting; 20 | 21 | /** 22 | * Usually MASConstraintMaker but could be a parent MASConstraint 23 | */ 24 | @property (nonatomic, weak) id delegate; 25 | 26 | /** 27 | * Based on a provided value type, is equal to calling: 28 | * NSNumber - setOffset: 29 | * NSValue with CGPoint - setPointOffset: 30 | * NSValue with CGSize - setSizeOffset: 31 | * NSValue with MASEdgeInsets - setInsets: 32 | */ 33 | - (void)setLayoutConstantWithValue:(NSValue *)value; 34 | 35 | @end 36 | 37 | 38 | @interface MASConstraint (Abstract) 39 | 40 | /** 41 | * Sets the constraint relation to given NSLayoutRelation 42 | * returns a block which accepts one of the following: 43 | * MASViewAttribute, UIView, NSValue, NSArray 44 | * see readme for more details. 45 | */ 46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation; 47 | 48 | /** 49 | * Override to set a custom chaining behaviour 50 | */ 51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 52 | 53 | @end 54 | 55 | 56 | @protocol MASConstraintDelegate 57 | 58 | /** 59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example 60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks 61 | */ 62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint; 63 | 64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * Enables Constraints to be created with chainable syntax 13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint) 14 | * or a group of NSLayoutConstraints (MASComposisteConstraint) 15 | */ 16 | @interface MASConstraint : NSObject 17 | 18 | // Chaining Support 19 | 20 | /** 21 | * Modifies the NSLayoutConstraint constant, 22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 24 | */ 25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets; 26 | 27 | /** 28 | * Modifies the NSLayoutConstraint constant, 29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 31 | */ 32 | - (MASConstraint * (^)(CGSize offset))sizeOffset; 33 | 34 | /** 35 | * Modifies the NSLayoutConstraint constant, 36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 38 | */ 39 | - (MASConstraint * (^)(CGPoint offset))centerOffset; 40 | 41 | /** 42 | * Modifies the NSLayoutConstraint constant 43 | */ 44 | - (MASConstraint * (^)(CGFloat offset))offset; 45 | 46 | /** 47 | * Modifies the NSLayoutConstraint constant based on a value type 48 | */ 49 | - (MASConstraint * (^)(NSValue *value))valueOffset; 50 | 51 | /** 52 | * Sets the NSLayoutConstraint multiplier property 53 | */ 54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy; 55 | 56 | /** 57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy 58 | */ 59 | - (MASConstraint * (^)(CGFloat divider))dividedBy; 60 | 61 | /** 62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority 63 | */ 64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority; 65 | 66 | /** 67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow 68 | */ 69 | - (MASConstraint * (^)())priorityLow; 70 | 71 | /** 72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium 73 | */ 74 | - (MASConstraint * (^)())priorityMedium; 75 | 76 | /** 77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh 78 | */ 79 | - (MASConstraint * (^)())priorityHigh; 80 | 81 | /** 82 | * Sets the constraint relation to NSLayoutRelationEqual 83 | * returns a block which accepts one of the following: 84 | * MASViewAttribute, UIView, NSValue, NSArray 85 | * see readme for more details. 86 | */ 87 | - (MASConstraint * (^)(id attr))equalTo; 88 | 89 | /** 90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual 91 | * returns a block which accepts one of the following: 92 | * MASViewAttribute, UIView, NSValue, NSArray 93 | * see readme for more details. 94 | */ 95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo; 96 | 97 | /** 98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual 99 | * returns a block which accepts one of the following: 100 | * MASViewAttribute, UIView, NSValue, NSArray 101 | * see readme for more details. 102 | */ 103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo; 104 | 105 | /** 106 | * Optional semantic property which has no effect but improves the readability of constraint 107 | */ 108 | - (MASConstraint *)with; 109 | 110 | /** 111 | * Optional semantic property which has no effect but improves the readability of constraint 112 | */ 113 | - (MASConstraint *)and; 114 | 115 | /** 116 | * Creates a new MASCompositeConstraint with the called attribute and reciever 117 | */ 118 | - (MASConstraint *)left; 119 | - (MASConstraint *)top; 120 | - (MASConstraint *)right; 121 | - (MASConstraint *)bottom; 122 | - (MASConstraint *)leading; 123 | - (MASConstraint *)trailing; 124 | - (MASConstraint *)width; 125 | - (MASConstraint *)height; 126 | - (MASConstraint *)centerX; 127 | - (MASConstraint *)centerY; 128 | - (MASConstraint *)baseline; 129 | 130 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 131 | 132 | - (MASConstraint *)firstBaseline; 133 | - (MASConstraint *)lastBaseline; 134 | 135 | #endif 136 | 137 | #if TARGET_OS_IPHONE || TARGET_OS_TV 138 | 139 | - (MASConstraint *)leftMargin; 140 | - (MASConstraint *)rightMargin; 141 | - (MASConstraint *)topMargin; 142 | - (MASConstraint *)bottomMargin; 143 | - (MASConstraint *)leadingMargin; 144 | - (MASConstraint *)trailingMargin; 145 | - (MASConstraint *)centerXWithinMargins; 146 | - (MASConstraint *)centerYWithinMargins; 147 | 148 | #endif 149 | 150 | 151 | /** 152 | * Sets the constraint debug name 153 | */ 154 | - (MASConstraint * (^)(id key))key; 155 | 156 | // NSLayoutConstraint constant Setters 157 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks 158 | 159 | /** 160 | * Modifies the NSLayoutConstraint constant, 161 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 162 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 163 | */ 164 | - (void)setInsets:(MASEdgeInsets)insets; 165 | 166 | /** 167 | * Modifies the NSLayoutConstraint constant, 168 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 169 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 170 | */ 171 | - (void)setSizeOffset:(CGSize)sizeOffset; 172 | 173 | /** 174 | * Modifies the NSLayoutConstraint constant, 175 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 176 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 177 | */ 178 | - (void)setCenterOffset:(CGPoint)centerOffset; 179 | 180 | /** 181 | * Modifies the NSLayoutConstraint constant 182 | */ 183 | - (void)setOffset:(CGFloat)offset; 184 | 185 | 186 | // NSLayoutConstraint Installation support 187 | 188 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 189 | /** 190 | * Whether or not to go through the animator proxy when modifying the constraint 191 | */ 192 | @property (nonatomic, copy, readonly) MASConstraint *animator; 193 | #endif 194 | 195 | /** 196 | * Activates an NSLayoutConstraint if it's supported by an OS. 197 | * Invokes install otherwise. 198 | */ 199 | - (void)activate; 200 | 201 | /** 202 | * Deactivates previously installed/activated NSLayoutConstraint. 203 | */ 204 | - (void)deactivate; 205 | 206 | /** 207 | * Creates a NSLayoutConstraint and adds it to the appropriate view. 208 | */ 209 | - (void)install; 210 | 211 | /** 212 | * Removes previously installed NSLayoutConstraint 213 | */ 214 | - (void)uninstall; 215 | 216 | @end 217 | 218 | 219 | /** 220 | * Convenience auto-boxing macros for MASConstraint methods. 221 | * 222 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax. 223 | * A potential drawback of this is that the unprefixed macros will appear in global scope. 224 | */ 225 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__))) 226 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 227 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 228 | 229 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__))) 230 | 231 | 232 | #ifdef MAS_SHORTHAND_GLOBALS 233 | 234 | #define equalTo(...) mas_equalTo(__VA_ARGS__) 235 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__) 236 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__) 237 | 238 | #define offset(...) mas_offset(__VA_ARGS__) 239 | 240 | #endif 241 | 242 | 243 | @interface MASConstraint (AutoboxingSupport) 244 | 245 | /** 246 | * Aliases to corresponding relation methods (for shorthand macros) 247 | * Also needed to aid autocompletion 248 | */ 249 | - (MASConstraint * (^)(id attr))mas_equalTo; 250 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo; 251 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo; 252 | 253 | /** 254 | * A dummy method to aid autocompletion 255 | */ 256 | - (MASConstraint * (^)(id offset))mas_offset; 257 | 258 | @end 259 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.m 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 1/20/14. 6 | // 7 | 8 | #import "MASConstraint.h" 9 | #import "MASConstraint+Private.h" 10 | 11 | #define MASMethodNotImplemented() \ 12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \ 13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \ 14 | userInfo:nil] 15 | 16 | @implementation MASConstraint 17 | 18 | #pragma mark - Init 19 | 20 | - (id)init { 21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly."); 22 | return [super init]; 23 | } 24 | 25 | #pragma mark - NSLayoutRelation proxies 26 | 27 | - (MASConstraint * (^)(id))equalTo { 28 | return ^id(id attribute) { 29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 30 | }; 31 | } 32 | 33 | - (MASConstraint * (^)(id))mas_equalTo { 34 | return ^id(id attribute) { 35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 36 | }; 37 | } 38 | 39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo { 40 | return ^id(id attribute) { 41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 42 | }; 43 | } 44 | 45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo { 46 | return ^id(id attribute) { 47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 48 | }; 49 | } 50 | 51 | - (MASConstraint * (^)(id))lessThanOrEqualTo { 52 | return ^id(id attribute) { 53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 54 | }; 55 | } 56 | 57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo { 58 | return ^id(id attribute) { 59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 60 | }; 61 | } 62 | 63 | #pragma mark - MASLayoutPriority proxies 64 | 65 | - (MASConstraint * (^)())priorityLow { 66 | return ^id{ 67 | self.priority(MASLayoutPriorityDefaultLow); 68 | return self; 69 | }; 70 | } 71 | 72 | - (MASConstraint * (^)())priorityMedium { 73 | return ^id{ 74 | self.priority(MASLayoutPriorityDefaultMedium); 75 | return self; 76 | }; 77 | } 78 | 79 | - (MASConstraint * (^)())priorityHigh { 80 | return ^id{ 81 | self.priority(MASLayoutPriorityDefaultHigh); 82 | return self; 83 | }; 84 | } 85 | 86 | #pragma mark - NSLayoutConstraint constant proxies 87 | 88 | - (MASConstraint * (^)(MASEdgeInsets))insets { 89 | return ^id(MASEdgeInsets insets){ 90 | self.insets = insets; 91 | return self; 92 | }; 93 | } 94 | 95 | - (MASConstraint * (^)(CGSize))sizeOffset { 96 | return ^id(CGSize offset) { 97 | self.sizeOffset = offset; 98 | return self; 99 | }; 100 | } 101 | 102 | - (MASConstraint * (^)(CGPoint))centerOffset { 103 | return ^id(CGPoint offset) { 104 | self.centerOffset = offset; 105 | return self; 106 | }; 107 | } 108 | 109 | - (MASConstraint * (^)(CGFloat))offset { 110 | return ^id(CGFloat offset){ 111 | self.offset = offset; 112 | return self; 113 | }; 114 | } 115 | 116 | - (MASConstraint * (^)(NSValue *value))valueOffset { 117 | return ^id(NSValue *offset) { 118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset); 119 | [self setLayoutConstantWithValue:offset]; 120 | return self; 121 | }; 122 | } 123 | 124 | - (MASConstraint * (^)(id offset))mas_offset { 125 | // Will never be called due to macro 126 | return nil; 127 | } 128 | 129 | #pragma mark - NSLayoutConstraint constant setter 130 | 131 | - (void)setLayoutConstantWithValue:(NSValue *)value { 132 | if ([value isKindOfClass:NSNumber.class]) { 133 | self.offset = [(NSNumber *)value doubleValue]; 134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) { 135 | CGPoint point; 136 | [value getValue:&point]; 137 | self.centerOffset = point; 138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) { 139 | CGSize size; 140 | [value getValue:&size]; 141 | self.sizeOffset = size; 142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) { 143 | MASEdgeInsets insets; 144 | [value getValue:&insets]; 145 | self.insets = insets; 146 | } else { 147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value); 148 | } 149 | } 150 | 151 | #pragma mark - Semantic properties 152 | 153 | - (MASConstraint *)with { 154 | return self; 155 | } 156 | 157 | - (MASConstraint *)and { 158 | return self; 159 | } 160 | 161 | #pragma mark - Chaining 162 | 163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute { 164 | MASMethodNotImplemented(); 165 | } 166 | 167 | - (MASConstraint *)left { 168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 169 | } 170 | 171 | - (MASConstraint *)top { 172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 173 | } 174 | 175 | - (MASConstraint *)right { 176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 177 | } 178 | 179 | - (MASConstraint *)bottom { 180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 181 | } 182 | 183 | - (MASConstraint *)leading { 184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 185 | } 186 | 187 | - (MASConstraint *)trailing { 188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 189 | } 190 | 191 | - (MASConstraint *)width { 192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 193 | } 194 | 195 | - (MASConstraint *)height { 196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 197 | } 198 | 199 | - (MASConstraint *)centerX { 200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 201 | } 202 | 203 | - (MASConstraint *)centerY { 204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 205 | } 206 | 207 | - (MASConstraint *)baseline { 208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 209 | } 210 | 211 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 212 | 213 | - (MASConstraint *)firstBaseline { 214 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; 215 | } 216 | - (MASConstraint *)lastBaseline { 217 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; 218 | } 219 | 220 | #endif 221 | 222 | #if TARGET_OS_IPHONE || TARGET_OS_TV 223 | 224 | - (MASConstraint *)leftMargin { 225 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; 226 | } 227 | 228 | - (MASConstraint *)rightMargin { 229 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; 230 | } 231 | 232 | - (MASConstraint *)topMargin { 233 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; 234 | } 235 | 236 | - (MASConstraint *)bottomMargin { 237 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; 238 | } 239 | 240 | - (MASConstraint *)leadingMargin { 241 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; 242 | } 243 | 244 | - (MASConstraint *)trailingMargin { 245 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; 246 | } 247 | 248 | - (MASConstraint *)centerXWithinMargins { 249 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 250 | } 251 | 252 | - (MASConstraint *)centerYWithinMargins { 253 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 254 | } 255 | 256 | #endif 257 | 258 | #pragma mark - Abstract 259 | 260 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); } 261 | 262 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); } 263 | 264 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); } 265 | 266 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); } 267 | 268 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); } 269 | 270 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } 271 | 272 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } 273 | 274 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } 275 | 276 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); } 277 | 278 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 279 | 280 | - (MASConstraint *)animator { MASMethodNotImplemented(); } 281 | 282 | #endif 283 | 284 | - (void)activate { MASMethodNotImplemented(); } 285 | 286 | - (void)deactivate { MASMethodNotImplemented(); } 287 | 288 | - (void)install { MASMethodNotImplemented(); } 289 | 290 | - (void)uninstall { MASMethodNotImplemented(); } 291 | 292 | @end 293 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASConstraintMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | typedef NS_OPTIONS(NSInteger, MASAttribute) { 13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft, 14 | MASAttributeRight = 1 << NSLayoutAttributeRight, 15 | MASAttributeTop = 1 << NSLayoutAttributeTop, 16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom, 17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading, 18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing, 19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth, 20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight, 21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX, 22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, 23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, 24 | 25 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 26 | 27 | MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline, 28 | MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline, 29 | 30 | #endif 31 | 32 | #if TARGET_OS_IPHONE || TARGET_OS_TV 33 | 34 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin, 35 | MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin, 36 | MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin, 37 | MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin, 38 | MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin, 39 | MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin, 40 | MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins, 41 | MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins, 42 | 43 | #endif 44 | 45 | }; 46 | 47 | /** 48 | * Provides factory methods for creating MASConstraints. 49 | * Constraints are collected until they are ready to be installed 50 | * 51 | */ 52 | @interface MASConstraintMaker : NSObject 53 | 54 | /** 55 | * The following properties return a new MASViewConstraint 56 | * with the first item set to the makers associated view and the appropriate MASViewAttribute 57 | */ 58 | @property (nonatomic, strong, readonly) MASConstraint *left; 59 | @property (nonatomic, strong, readonly) MASConstraint *top; 60 | @property (nonatomic, strong, readonly) MASConstraint *right; 61 | @property (nonatomic, strong, readonly) MASConstraint *bottom; 62 | @property (nonatomic, strong, readonly) MASConstraint *leading; 63 | @property (nonatomic, strong, readonly) MASConstraint *trailing; 64 | @property (nonatomic, strong, readonly) MASConstraint *width; 65 | @property (nonatomic, strong, readonly) MASConstraint *height; 66 | @property (nonatomic, strong, readonly) MASConstraint *centerX; 67 | @property (nonatomic, strong, readonly) MASConstraint *centerY; 68 | @property (nonatomic, strong, readonly) MASConstraint *baseline; 69 | 70 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 71 | 72 | @property (nonatomic, strong, readonly) MASConstraint *firstBaseline; 73 | @property (nonatomic, strong, readonly) MASConstraint *lastBaseline; 74 | 75 | #endif 76 | 77 | #if TARGET_OS_IPHONE || TARGET_OS_TV 78 | 79 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin; 80 | @property (nonatomic, strong, readonly) MASConstraint *rightMargin; 81 | @property (nonatomic, strong, readonly) MASConstraint *topMargin; 82 | @property (nonatomic, strong, readonly) MASConstraint *bottomMargin; 83 | @property (nonatomic, strong, readonly) MASConstraint *leadingMargin; 84 | @property (nonatomic, strong, readonly) MASConstraint *trailingMargin; 85 | @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins; 86 | @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins; 87 | 88 | #endif 89 | 90 | /** 91 | * Returns a block which creates a new MASCompositeConstraint with the first item set 92 | * to the makers associated view and children corresponding to the set bits in the 93 | * MASAttribute parameter. Combine multiple attributes via binary-or. 94 | */ 95 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs); 96 | 97 | /** 98 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges 99 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right) 100 | * with the first item set to the makers associated view 101 | */ 102 | @property (nonatomic, strong, readonly) MASConstraint *edges; 103 | 104 | /** 105 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize 106 | * which generates the appropriate MASViewConstraint children (width, height) 107 | * with the first item set to the makers associated view 108 | */ 109 | @property (nonatomic, strong, readonly) MASConstraint *size; 110 | 111 | /** 112 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter 113 | * which generates the appropriate MASViewConstraint children (centerX, centerY) 114 | * with the first item set to the makers associated view 115 | */ 116 | @property (nonatomic, strong, readonly) MASConstraint *center; 117 | 118 | /** 119 | * Whether or not to check for an existing constraint instead of adding constraint 120 | */ 121 | @property (nonatomic, assign) BOOL updateExisting; 122 | 123 | /** 124 | * Whether or not to remove existing constraints prior to installing 125 | */ 126 | @property (nonatomic, assign) BOOL removeExisting; 127 | 128 | /** 129 | * initialises the maker with a default view 130 | * 131 | * @param view any MASConstrait are created with this view as the first item 132 | * 133 | * @return a new MASConstraintMaker 134 | */ 135 | - (id)initWithView:(MAS_VIEW *)view; 136 | 137 | /** 138 | * Calls install method on any MASConstraints which have been created by this maker 139 | * 140 | * @return an array of all the installed MASConstraints 141 | */ 142 | - (NSArray *)install; 143 | 144 | - (MASConstraint * (^)(dispatch_block_t))group; 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASLayoutConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * When you are debugging or printing the constraints attached to a view this subclass 13 | * makes it easier to identify which constraints have been created via Masonry 14 | */ 15 | @interface MASLayoutConstraint : NSLayoutConstraint 16 | 17 | /** 18 | * a key to associate with this constraint 19 | */ 20 | @property (nonatomic, strong) id mas_key; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASLayoutConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASLayoutConstraint.h" 10 | 11 | @implementation MASLayoutConstraint 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASUtilities.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 19/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | 13 | #if TARGET_OS_IPHONE || TARGET_OS_TV 14 | 15 | #import 16 | #define MAS_VIEW UIView 17 | #define MAS_VIEW_CONTROLLER UIViewController 18 | #define MASEdgeInsets UIEdgeInsets 19 | 20 | typedef UILayoutPriority MASLayoutPriority; 21 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired; 22 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh; 23 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500; 24 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow; 25 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel; 26 | 27 | #elif TARGET_OS_MAC 28 | 29 | #import 30 | #define MAS_VIEW NSView 31 | #define MASEdgeInsets NSEdgeInsets 32 | 33 | typedef NSLayoutPriority MASLayoutPriority; 34 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired; 35 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh; 36 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow; 37 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501; 38 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut; 39 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow; 40 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow; 41 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression; 42 | 43 | #endif 44 | 45 | /** 46 | * Allows you to attach keys to objects matching the variable names passed. 47 | * 48 | * view1.mas_key = @"view1", view2.mas_key = @"view2"; 49 | * 50 | * is equivalent to: 51 | * 52 | * MASAttachKeys(view1, view2); 53 | */ 54 | #define MASAttachKeys(...) \ 55 | { \ 56 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \ 57 | for (id key in keyPairs.allKeys) { \ 58 | id obj = keyPairs[key]; \ 59 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \ 60 | @"Cannot attach mas_key to %@", obj); \ 61 | [obj setMas_key:key]; \ 62 | } \ 63 | } 64 | 65 | /** 66 | * Used to create object hashes 67 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html 68 | */ 69 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger)) 70 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch))) 71 | 72 | /** 73 | * Given a scalar or struct value, wraps it in NSValue 74 | * Based on EXPObjectify: https://github.com/specta/expecta 75 | */ 76 | static inline id _MASBoxValue(const char *type, ...) { 77 | va_list v; 78 | va_start(v, type); 79 | id obj = nil; 80 | if (strcmp(type, @encode(id)) == 0) { 81 | id actual = va_arg(v, id); 82 | obj = actual; 83 | } else if (strcmp(type, @encode(CGPoint)) == 0) { 84 | CGPoint actual = (CGPoint)va_arg(v, CGPoint); 85 | obj = [NSValue value:&actual withObjCType:type]; 86 | } else if (strcmp(type, @encode(CGSize)) == 0) { 87 | CGSize actual = (CGSize)va_arg(v, CGSize); 88 | obj = [NSValue value:&actual withObjCType:type]; 89 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { 90 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); 91 | obj = [NSValue value:&actual withObjCType:type]; 92 | } else if (strcmp(type, @encode(double)) == 0) { 93 | double actual = (double)va_arg(v, double); 94 | obj = [NSNumber numberWithDouble:actual]; 95 | } else if (strcmp(type, @encode(float)) == 0) { 96 | float actual = (float)va_arg(v, double); 97 | obj = [NSNumber numberWithFloat:actual]; 98 | } else if (strcmp(type, @encode(int)) == 0) { 99 | int actual = (int)va_arg(v, int); 100 | obj = [NSNumber numberWithInt:actual]; 101 | } else if (strcmp(type, @encode(long)) == 0) { 102 | long actual = (long)va_arg(v, long); 103 | obj = [NSNumber numberWithLong:actual]; 104 | } else if (strcmp(type, @encode(long long)) == 0) { 105 | long long actual = (long long)va_arg(v, long long); 106 | obj = [NSNumber numberWithLongLong:actual]; 107 | } else if (strcmp(type, @encode(short)) == 0) { 108 | short actual = (short)va_arg(v, int); 109 | obj = [NSNumber numberWithShort:actual]; 110 | } else if (strcmp(type, @encode(char)) == 0) { 111 | char actual = (char)va_arg(v, int); 112 | obj = [NSNumber numberWithChar:actual]; 113 | } else if (strcmp(type, @encode(bool)) == 0) { 114 | bool actual = (bool)va_arg(v, int); 115 | obj = [NSNumber numberWithBool:actual]; 116 | } else if (strcmp(type, @encode(unsigned char)) == 0) { 117 | unsigned char actual = (unsigned char)va_arg(v, unsigned int); 118 | obj = [NSNumber numberWithUnsignedChar:actual]; 119 | } else if (strcmp(type, @encode(unsigned int)) == 0) { 120 | unsigned int actual = (unsigned int)va_arg(v, unsigned int); 121 | obj = [NSNumber numberWithUnsignedInt:actual]; 122 | } else if (strcmp(type, @encode(unsigned long)) == 0) { 123 | unsigned long actual = (unsigned long)va_arg(v, unsigned long); 124 | obj = [NSNumber numberWithUnsignedLong:actual]; 125 | } else if (strcmp(type, @encode(unsigned long long)) == 0) { 126 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); 127 | obj = [NSNumber numberWithUnsignedLongLong:actual]; 128 | } else if (strcmp(type, @encode(unsigned short)) == 0) { 129 | unsigned short actual = (unsigned short)va_arg(v, unsigned int); 130 | obj = [NSNumber numberWithUnsignedShort:actual]; 131 | } 132 | va_end(v); 133 | return obj; 134 | } 135 | 136 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) 137 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASViewAttribute.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * An immutable tuple which stores the view and the related NSLayoutAttribute. 13 | * Describes part of either the left or right hand side of a constraint equation 14 | */ 15 | @interface MASViewAttribute : NSObject 16 | 17 | /** 18 | * The view which the reciever relates to. Can be nil if item is not a view. 19 | */ 20 | @property (nonatomic, weak, readonly) MAS_VIEW *view; 21 | 22 | /** 23 | * The item which the reciever relates to. 24 | */ 25 | @property (nonatomic, weak, readonly) id item; 26 | 27 | /** 28 | * The attribute which the reciever relates to 29 | */ 30 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute; 31 | 32 | /** 33 | * Convenience initializer. 34 | */ 35 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute; 36 | 37 | /** 38 | * The designated initializer. 39 | */ 40 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute; 41 | 42 | /** 43 | * Determine whether the layoutAttribute is a size attribute 44 | * 45 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight 46 | */ 47 | - (BOOL)isSizeAttribute; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASViewAttribute.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | 11 | @implementation MASViewAttribute 12 | 13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute { 14 | self = [self initWithView:view item:view layoutAttribute:layoutAttribute]; 15 | return self; 16 | } 17 | 18 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute { 19 | self = [super init]; 20 | if (!self) return nil; 21 | 22 | _view = view; 23 | _item = item; 24 | _layoutAttribute = layoutAttribute; 25 | 26 | return self; 27 | } 28 | 29 | - (BOOL)isSizeAttribute { 30 | return self.layoutAttribute == NSLayoutAttributeWidth 31 | || self.layoutAttribute == NSLayoutAttributeHeight; 32 | } 33 | 34 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute { 35 | if ([viewAttribute isKindOfClass:self.class]) { 36 | return self.view == viewAttribute.view 37 | && self.layoutAttribute == viewAttribute.layoutAttribute; 38 | } 39 | return [super isEqual:viewAttribute]; 40 | } 41 | 42 | - (NSUInteger)hash { 43 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/MASViewConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | #import "MASUtilities.h" 13 | 14 | /** 15 | * A single constraint. 16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view 17 | */ 18 | @interface MASViewConstraint : MASConstraint 19 | 20 | /** 21 | * First item/view and first attribute of the NSLayoutConstraint 22 | */ 23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute; 24 | 25 | /** 26 | * Second item/view and second attribute of the NSLayoutConstraint 27 | */ 28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute; 29 | 30 | /** 31 | * initialises the MASViewConstraint with the first part of the equation 32 | * 33 | * @param firstViewAttribute view.mas_left, view.mas_width etc. 34 | * 35 | * @return a new view constraint 36 | */ 37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute; 38 | 39 | /** 40 | * Returns all MASViewConstraints installed with this view as a first item. 41 | * 42 | * @param view A view to retrieve constraints for. 43 | * 44 | * @return An array of MASViewConstraints. 45 | */ 46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/Masonry.h: -------------------------------------------------------------------------------- 1 | // 2 | // Masonry.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Masonry. 12 | FOUNDATION_EXPORT double MasonryVersionNumber; 13 | 14 | //! Project version string for Masonry. 15 | FOUNDATION_EXPORT const unsigned char MasonryVersionString[]; 16 | 17 | #import "MASUtilities.h" 18 | #import "View+MASAdditions.h" 19 | #import "View+MASShorthandAdditions.h" 20 | #import "ViewController+MASAdditions.h" 21 | #import "NSArray+MASAdditions.h" 22 | #import "NSArray+MASShorthandAdditions.h" 23 | #import "MASConstraint.h" 24 | #import "MASCompositeConstraint.h" 25 | #import "MASViewAttribute.h" 26 | #import "MASViewConstraint.h" 27 | #import "MASConstraintMaker.h" 28 | #import "MASLayoutConstraint.h" 29 | #import "NSLayoutConstraint+MASDebugAdditions.h" 30 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/NSArray+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.h 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | typedef NS_ENUM(NSUInteger, MASAxisType) { 14 | MASAxisTypeHorizontal, 15 | MASAxisTypeVertical 16 | }; 17 | 18 | @interface NSArray (MASAdditions) 19 | 20 | /** 21 | * Creates a MASConstraintMaker with each view in the callee. 22 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view 23 | * 24 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 25 | * 26 | * @return Array of created MASConstraints 27 | */ 28 | - (NSArray *)mas_makeConstraints:(void (^)(MASConstraintMaker *make))block; 29 | 30 | /** 31 | * Creates a MASConstraintMaker with each view in the callee. 32 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 33 | * If an existing constraint exists then it will be updated instead. 34 | * 35 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 36 | * 37 | * @return Array of created/updated MASConstraints 38 | */ 39 | - (NSArray *)mas_updateConstraints:(void (^)(MASConstraintMaker *make))block; 40 | 41 | /** 42 | * Creates a MASConstraintMaker with each view in the callee. 43 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 44 | * All constraints previously installed for the views will be removed. 45 | * 46 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 47 | * 48 | * @return Array of created/updated MASConstraints 49 | */ 50 | - (NSArray *)mas_remakeConstraints:(void (^)(MASConstraintMaker *make))block; 51 | 52 | /** 53 | * distribute with fixed spacing 54 | * 55 | * @param axisType which axis to distribute items along 56 | * @param fixedSpacing the spacing between each item 57 | * @param leadSpacing the spacing before the first item and the container 58 | * @param tailSpacing the spacing after the last item and the container 59 | */ 60 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; 61 | 62 | /** 63 | * distribute with fixed item size 64 | * 65 | * @param axisType which axis to distribute items along 66 | * @param fixedItemLength the fixed length of each item 67 | * @param leadSpacing the spacing before the first item and the container 68 | * @param tailSpacing the spacing after the last item and the container 69 | */ 70 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/NSArray+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.m 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | #import "View+MASAdditions.h" 11 | 12 | @implementation NSArray (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { 15 | NSMutableArray *constraints = [NSMutableArray array]; 16 | for (MAS_VIEW *view in self) { 17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]]; 19 | } 20 | return constraints; 21 | } 22 | 23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { 24 | NSMutableArray *constraints = [NSMutableArray array]; 25 | for (MAS_VIEW *view in self) { 26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]]; 28 | } 29 | return constraints; 30 | } 31 | 32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 33 | NSMutableArray *constraints = [NSMutableArray array]; 34 | for (MAS_VIEW *view in self) { 35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]]; 37 | } 38 | return constraints; 39 | } 40 | 41 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing { 42 | if (self.count < 2) { 43 | NSAssert(self.count>1,@"views to distribute need to bigger than one"); 44 | return; 45 | } 46 | 47 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews]; 48 | if (axisType == MASAxisTypeHorizontal) { 49 | MAS_VIEW *prev; 50 | for (int i = 0; i < self.count; i++) { 51 | MAS_VIEW *v = self[i]; 52 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 53 | if (prev) { 54 | make.width.equalTo(prev); 55 | make.left.equalTo(prev.mas_right).offset(fixedSpacing); 56 | if (i == self.count - 1) {//last one 57 | make.right.equalTo(tempSuperView).offset(-tailSpacing); 58 | } 59 | } 60 | else {//first one 61 | make.left.equalTo(tempSuperView).offset(leadSpacing); 62 | } 63 | 64 | }]; 65 | prev = v; 66 | } 67 | } 68 | else { 69 | MAS_VIEW *prev; 70 | for (int i = 0; i < self.count; i++) { 71 | MAS_VIEW *v = self[i]; 72 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 73 | if (prev) { 74 | make.height.equalTo(prev); 75 | make.top.equalTo(prev.mas_bottom).offset(fixedSpacing); 76 | if (i == self.count - 1) {//last one 77 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); 78 | } 79 | } 80 | else {//first one 81 | make.top.equalTo(tempSuperView).offset(leadSpacing); 82 | } 83 | 84 | }]; 85 | prev = v; 86 | } 87 | } 88 | } 89 | 90 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing { 91 | if (self.count < 2) { 92 | NSAssert(self.count>1,@"views to distribute need to bigger than one"); 93 | return; 94 | } 95 | 96 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews]; 97 | if (axisType == MASAxisTypeHorizontal) { 98 | MAS_VIEW *prev; 99 | for (int i = 0; i < self.count; i++) { 100 | MAS_VIEW *v = self[i]; 101 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 102 | make.width.equalTo(@(fixedItemLength)); 103 | if (prev) { 104 | if (i == self.count - 1) {//last one 105 | make.right.equalTo(tempSuperView).offset(-tailSpacing); 106 | } 107 | else { 108 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); 109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); 110 | } 111 | } 112 | else {//first one 113 | make.left.equalTo(tempSuperView).offset(leadSpacing); 114 | } 115 | }]; 116 | prev = v; 117 | } 118 | } 119 | else { 120 | MAS_VIEW *prev; 121 | for (int i = 0; i < self.count; i++) { 122 | MAS_VIEW *v = self[i]; 123 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 124 | make.height.equalTo(@(fixedItemLength)); 125 | if (prev) { 126 | if (i == self.count - 1) {//last one 127 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); 128 | } 129 | else { 130 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); 131 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); 132 | } 133 | } 134 | else {//first one 135 | make.top.equalTo(tempSuperView).offset(leadSpacing); 136 | } 137 | }]; 138 | prev = v; 139 | } 140 | } 141 | } 142 | 143 | - (MAS_VIEW *)mas_commonSuperviewOfViews 144 | { 145 | MAS_VIEW *commonSuperview = nil; 146 | MAS_VIEW *previousView = nil; 147 | for (id object in self) { 148 | if ([object isKindOfClass:[MAS_VIEW class]]) { 149 | MAS_VIEW *view = (MAS_VIEW *)object; 150 | if (previousView) { 151 | commonSuperview = [view mas_closestCommonSuperview:commonSuperview]; 152 | } else { 153 | commonSuperview = view; 154 | } 155 | previousView = view; 156 | } 157 | } 158 | NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); 159 | return commonSuperview; 160 | } 161 | 162 | @end 163 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/NSArray+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand array additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface NSArray (MASShorthandAdditions) 18 | 19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 22 | 23 | @end 24 | 25 | @implementation NSArray (MASShorthandAdditions) 26 | 27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 28 | return [self mas_makeConstraints:block]; 29 | } 30 | 31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 32 | return [self mas_updateConstraints:block]; 33 | } 34 | 35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 36 | return [self mas_remakeConstraints:block]; 37 | } 38 | 39 | @end 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/NSLayoutConstraint+MASDebugAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * makes debug and log output of NSLayoutConstraints more readable 13 | */ 14 | @interface NSLayoutConstraint (MASDebugAdditions) 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/NSLayoutConstraint+MASDebugAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSLayoutConstraint+MASDebugAdditions.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | 13 | @implementation NSLayoutConstraint (MASDebugAdditions) 14 | 15 | #pragma mark - description maps 16 | 17 | + (NSDictionary *)layoutRelationDescriptionsByValue { 18 | static dispatch_once_t once; 19 | static NSDictionary *descriptionMap; 20 | dispatch_once(&once, ^{ 21 | descriptionMap = @{ 22 | @(NSLayoutRelationEqual) : @"==", 23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=", 24 | @(NSLayoutRelationLessThanOrEqual) : @"<=", 25 | }; 26 | }); 27 | return descriptionMap; 28 | } 29 | 30 | + (NSDictionary *)layoutAttributeDescriptionsByValue { 31 | static dispatch_once_t once; 32 | static NSDictionary *descriptionMap; 33 | dispatch_once(&once, ^{ 34 | descriptionMap = @{ 35 | @(NSLayoutAttributeTop) : @"top", 36 | @(NSLayoutAttributeLeft) : @"left", 37 | @(NSLayoutAttributeBottom) : @"bottom", 38 | @(NSLayoutAttributeRight) : @"right", 39 | @(NSLayoutAttributeLeading) : @"leading", 40 | @(NSLayoutAttributeTrailing) : @"trailing", 41 | @(NSLayoutAttributeWidth) : @"width", 42 | @(NSLayoutAttributeHeight) : @"height", 43 | @(NSLayoutAttributeCenterX) : @"centerX", 44 | @(NSLayoutAttributeCenterY) : @"centerY", 45 | @(NSLayoutAttributeBaseline) : @"baseline", 46 | 47 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 48 | @(NSLayoutAttributeFirstBaseline) : @"firstBaseline", 49 | @(NSLayoutAttributeLastBaseline) : @"lastBaseline", 50 | #endif 51 | 52 | #if TARGET_OS_IPHONE || TARGET_OS_TV 53 | @(NSLayoutAttributeLeftMargin) : @"leftMargin", 54 | @(NSLayoutAttributeRightMargin) : @"rightMargin", 55 | @(NSLayoutAttributeTopMargin) : @"topMargin", 56 | @(NSLayoutAttributeBottomMargin) : @"bottomMargin", 57 | @(NSLayoutAttributeLeadingMargin) : @"leadingMargin", 58 | @(NSLayoutAttributeTrailingMargin) : @"trailingMargin", 59 | @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins", 60 | @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins", 61 | #endif 62 | 63 | }; 64 | 65 | }); 66 | return descriptionMap; 67 | } 68 | 69 | 70 | + (NSDictionary *)layoutPriorityDescriptionsByValue { 71 | static dispatch_once_t once; 72 | static NSDictionary *descriptionMap; 73 | dispatch_once(&once, ^{ 74 | #if TARGET_OS_IPHONE || TARGET_OS_TV 75 | descriptionMap = @{ 76 | @(MASLayoutPriorityDefaultHigh) : @"high", 77 | @(MASLayoutPriorityDefaultLow) : @"low", 78 | @(MASLayoutPriorityDefaultMedium) : @"medium", 79 | @(MASLayoutPriorityRequired) : @"required", 80 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size", 81 | }; 82 | #elif TARGET_OS_MAC 83 | descriptionMap = @{ 84 | @(MASLayoutPriorityDefaultHigh) : @"high", 85 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window", 86 | @(MASLayoutPriorityDefaultMedium) : @"medium", 87 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put", 88 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window", 89 | @(MASLayoutPriorityDefaultLow) : @"low", 90 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size", 91 | @(MASLayoutPriorityRequired) : @"required", 92 | }; 93 | #endif 94 | }); 95 | return descriptionMap; 96 | } 97 | 98 | #pragma mark - description override 99 | 100 | + (NSString *)descriptionForObject:(id)obj { 101 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) { 102 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]]; 103 | } 104 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj]; 105 | } 106 | 107 | - (NSString *)description { 108 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"]; 109 | 110 | [description appendString:[self.class descriptionForObject:self]]; 111 | 112 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]]; 113 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) { 114 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.firstAttribute)]]; 115 | } 116 | 117 | [description appendFormat:@" %@", self.class.layoutRelationDescriptionsByValue[@(self.relation)]]; 118 | 119 | if (self.secondItem) { 120 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]]; 121 | } 122 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) { 123 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.secondAttribute)]]; 124 | } 125 | 126 | if (self.multiplier != 1) { 127 | [description appendFormat:@" * %g", self.multiplier]; 128 | } 129 | 130 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) { 131 | [description appendFormat:@" %g", self.constant]; 132 | } else { 133 | if (self.constant) { 134 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)]; 135 | } 136 | } 137 | 138 | if (self.priority != MASLayoutPriorityRequired) { 139 | [description appendFormat:@" ^%@", self.class.layoutPriorityDescriptionsByValue[@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]]; 140 | } 141 | 142 | [description appendString:@">"]; 143 | return description; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/View+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | /** 14 | * Provides constraint maker block 15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs 16 | */ 17 | @interface MAS_VIEW (MASAdditions) 18 | 19 | /** 20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute 21 | */ 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX; 31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; 32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; 33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); 34 | 35 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 36 | 37 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline; 38 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline; 39 | 40 | #endif 41 | 42 | #if TARGET_OS_IPHONE || TARGET_OS_TV 43 | 44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin; 45 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin; 46 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin; 47 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin; 48 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin; 49 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin; 50 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins; 51 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins; 52 | 53 | #endif 54 | 55 | /** 56 | * a key to associate with this view 57 | */ 58 | @property (nonatomic, strong) id mas_key; 59 | 60 | /** 61 | * Finds the closest common superview between this view and another view 62 | * 63 | * @param view other view 64 | * 65 | * @return returns nil if common superview could not be found 66 | */ 67 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view; 68 | 69 | /** 70 | * Creates a MASConstraintMaker with the callee view. 71 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing 72 | * 73 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 74 | * 75 | * @return Array of created MASConstraints 76 | */ 77 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; 78 | 79 | /** 80 | * Creates a MASConstraintMaker with the callee view. 81 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 82 | * If an existing constraint exists then it will be updated instead. 83 | * 84 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 85 | * 86 | * @return Array of created/updated MASConstraints 87 | */ 88 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; 89 | 90 | /** 91 | * Creates a MASConstraintMaker with the callee view. 92 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 93 | * All constraints previously installed for the view will be removed. 94 | * 95 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 96 | * 97 | * @return Array of created/updated MASConstraints 98 | */ 99 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/View+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | #import 11 | 12 | @implementation MAS_VIEW (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block { 15 | self.translatesAutoresizingMaskIntoConstraints = NO; 16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 17 | block(constraintMaker); 18 | return [constraintMaker install]; 19 | } 20 | 21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { 22 | self.translatesAutoresizingMaskIntoConstraints = NO; 23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 24 | constraintMaker.updateExisting = YES; 25 | block(constraintMaker); 26 | return [constraintMaker install]; 27 | } 28 | 29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 30 | self.translatesAutoresizingMaskIntoConstraints = NO; 31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 32 | constraintMaker.removeExisting = YES; 33 | block(constraintMaker); 34 | return [constraintMaker install]; 35 | } 36 | 37 | #pragma mark - NSLayoutAttribute properties 38 | 39 | - (MASViewAttribute *)mas_left { 40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft]; 41 | } 42 | 43 | - (MASViewAttribute *)mas_top { 44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop]; 45 | } 46 | 47 | - (MASViewAttribute *)mas_right { 48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight]; 49 | } 50 | 51 | - (MASViewAttribute *)mas_bottom { 52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom]; 53 | } 54 | 55 | - (MASViewAttribute *)mas_leading { 56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading]; 57 | } 58 | 59 | - (MASViewAttribute *)mas_trailing { 60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing]; 61 | } 62 | 63 | - (MASViewAttribute *)mas_width { 64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth]; 65 | } 66 | 67 | - (MASViewAttribute *)mas_height { 68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight]; 69 | } 70 | 71 | - (MASViewAttribute *)mas_centerX { 72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX]; 73 | } 74 | 75 | - (MASViewAttribute *)mas_centerY { 76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY]; 77 | } 78 | 79 | - (MASViewAttribute *)mas_baseline { 80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline]; 81 | } 82 | 83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute 84 | { 85 | return ^(NSLayoutAttribute attr) { 86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr]; 87 | }; 88 | } 89 | 90 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 91 | 92 | - (MASViewAttribute *)mas_firstBaseline { 93 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeFirstBaseline]; 94 | } 95 | - (MASViewAttribute *)mas_lastBaseline { 96 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline]; 97 | } 98 | 99 | #endif 100 | 101 | #if TARGET_OS_IPHONE || TARGET_OS_TV 102 | 103 | - (MASViewAttribute *)mas_leftMargin { 104 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin]; 105 | } 106 | 107 | - (MASViewAttribute *)mas_rightMargin { 108 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin]; 109 | } 110 | 111 | - (MASViewAttribute *)mas_topMargin { 112 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin]; 113 | } 114 | 115 | - (MASViewAttribute *)mas_bottomMargin { 116 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin]; 117 | } 118 | 119 | - (MASViewAttribute *)mas_leadingMargin { 120 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin]; 121 | } 122 | 123 | - (MASViewAttribute *)mas_trailingMargin { 124 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin]; 125 | } 126 | 127 | - (MASViewAttribute *)mas_centerXWithinMargins { 128 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 129 | } 130 | 131 | - (MASViewAttribute *)mas_centerYWithinMargins { 132 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 133 | } 134 | 135 | #endif 136 | 137 | #pragma mark - associated properties 138 | 139 | - (id)mas_key { 140 | return objc_getAssociatedObject(self, @selector(mas_key)); 141 | } 142 | 143 | - (void)setMas_key:(id)key { 144 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 145 | } 146 | 147 | #pragma mark - heirachy 148 | 149 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view { 150 | MAS_VIEW *closestCommonSuperview = nil; 151 | 152 | MAS_VIEW *secondViewSuperview = view; 153 | while (!closestCommonSuperview && secondViewSuperview) { 154 | MAS_VIEW *firstViewSuperview = self; 155 | while (!closestCommonSuperview && firstViewSuperview) { 156 | if (secondViewSuperview == firstViewSuperview) { 157 | closestCommonSuperview = secondViewSuperview; 158 | } 159 | firstViewSuperview = firstViewSuperview.superview; 160 | } 161 | secondViewSuperview = secondViewSuperview.superview; 162 | } 163 | return closestCommonSuperview; 164 | } 165 | 166 | @end 167 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/View+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand view additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface MAS_VIEW (MASShorthandAdditions) 18 | 19 | @property (nonatomic, strong, readonly) MASViewAttribute *left; 20 | @property (nonatomic, strong, readonly) MASViewAttribute *top; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *right; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *width; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *height; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); 31 | 32 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 33 | 34 | @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline; 35 | @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline; 36 | 37 | #endif 38 | 39 | #if TARGET_OS_IPHONE || TARGET_OS_TV 40 | 41 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin; 42 | @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin; 43 | @property (nonatomic, strong, readonly) MASViewAttribute *topMargin; 44 | @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin; 45 | @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin; 46 | @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin; 47 | @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins; 48 | @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins; 49 | 50 | #endif 51 | 52 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 53 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 54 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 55 | 56 | @end 57 | 58 | #define MAS_ATTR_FORWARD(attr) \ 59 | - (MASViewAttribute *)attr { \ 60 | return [self mas_##attr]; \ 61 | } 62 | 63 | @implementation MAS_VIEW (MASShorthandAdditions) 64 | 65 | MAS_ATTR_FORWARD(top); 66 | MAS_ATTR_FORWARD(left); 67 | MAS_ATTR_FORWARD(bottom); 68 | MAS_ATTR_FORWARD(right); 69 | MAS_ATTR_FORWARD(leading); 70 | MAS_ATTR_FORWARD(trailing); 71 | MAS_ATTR_FORWARD(width); 72 | MAS_ATTR_FORWARD(height); 73 | MAS_ATTR_FORWARD(centerX); 74 | MAS_ATTR_FORWARD(centerY); 75 | MAS_ATTR_FORWARD(baseline); 76 | 77 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 78 | 79 | MAS_ATTR_FORWARD(firstBaseline); 80 | MAS_ATTR_FORWARD(lastBaseline); 81 | 82 | #endif 83 | 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV 85 | 86 | MAS_ATTR_FORWARD(leftMargin); 87 | MAS_ATTR_FORWARD(rightMargin); 88 | MAS_ATTR_FORWARD(topMargin); 89 | MAS_ATTR_FORWARD(bottomMargin); 90 | MAS_ATTR_FORWARD(leadingMargin); 91 | MAS_ATTR_FORWARD(trailingMargin); 92 | MAS_ATTR_FORWARD(centerXWithinMargins); 93 | MAS_ATTR_FORWARD(centerYWithinMargins); 94 | 95 | #endif 96 | 97 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute { 98 | return [self mas_attribute]; 99 | } 100 | 101 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 102 | return [self mas_makeConstraints:block]; 103 | } 104 | 105 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 106 | return [self mas_updateConstraints:block]; 107 | } 108 | 109 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 110 | return [self mas_remakeConstraints:block]; 111 | } 112 | 113 | @end 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/ViewController+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Craig Siemens on 2015-06-23. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | #ifdef MAS_VIEW_CONTROLLER 14 | 15 | @interface MAS_VIEW_CONTROLLER (MASAdditions) 16 | 17 | /** 18 | * following properties return a new MASViewAttribute with appropriate UILayoutGuide and NSLayoutAttribute 19 | */ 20 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom; 26 | 27 | 28 | @end 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Demo/Demo/Masonry/ViewController+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Craig Siemens on 2015-06-23. 6 | // 7 | // 8 | 9 | #import "ViewController+MASAdditions.h" 10 | 11 | #ifdef MAS_VIEW_CONTROLLER 12 | 13 | @implementation MAS_VIEW_CONTROLLER (MASAdditions) 14 | 15 | - (MASViewAttribute *)mas_topLayoutGuide { 16 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 17 | } 18 | - (MASViewAttribute *)mas_topLayoutGuideTop { 19 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 20 | } 21 | - (MASViewAttribute *)mas_topLayoutGuideBottom { 22 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 23 | } 24 | 25 | - (MASViewAttribute *)mas_bottomLayoutGuide { 26 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 27 | } 28 | - (MASViewAttribute *)mas_bottomLayoutGuideTop { 29 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 30 | } 31 | - (MASViewAttribute *)mas_bottomLayoutGuideBottom { 32 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 33 | } 34 | 35 | 36 | 37 | @end 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Demo/Demo/PrefixHeader.pch: -------------------------------------------------------------------------------- 1 | // 2 | // PrefixHeader.pch 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #ifndef PrefixHeader_pch 10 | #define PrefixHeader_pch 11 | // Include any system framework and library headers here that should be included in all compilation units. 12 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. 13 | 14 | #import "WHStoryMakerHeader.h" 15 | 16 | #endif /* PrefixHeader_pch */ 17 | -------------------------------------------------------------------------------- /Demo/Demo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Demo/Demo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "StoryMakeImageEditorViewController.h" 11 | 12 | #import 13 | #import 14 | 15 | @interface ViewController () 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | 24 | UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; 25 | button.center = self.view.center; 26 | [button setTitle:@"打开相册" forState:UIControlStateNormal]; 27 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 28 | [button setBackgroundColor:[UIColor grayColor]]; 29 | [button addTarget:self action:@selector(openAlbum) forControlEvents:UIControlEventTouchUpInside]; 30 | [self.view addSubview:button]; 31 | 32 | 33 | UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; 34 | button2.center = CGPointMake(self.view.center.x, self.view.center.y + 60); 35 | [button2 setTitle:@"使用测试图" forState:UIControlStateNormal]; 36 | [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 37 | [button2 setBackgroundColor:[UIColor grayColor]]; 38 | [button2 addTarget:self action:@selector(openTestImage) forControlEvents:UIControlEventTouchUpInside]; 39 | [self.view addSubview:button2]; 40 | } 41 | 42 | - (void)openTestImage{ 43 | UIImage *image = [UIImage imageNamed:@"bgStory.jpg"]; 44 | StoryMakeImageEditorViewController *storyMakerVc = [[StoryMakeImageEditorViewController alloc] initWithImage:image]; 45 | [self presentViewController:storyMakerVc animated:YES completion:nil]; 46 | } 47 | 48 | - (void)openAlbum{ 49 | UIImagePickerController *imagePicker= [[UIImagePickerController alloc] init]; 50 | imagePicker.delegate = self; 51 | imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 52 | imagePicker.mediaTypes = @[(NSString *)kUTTypeImage]; 53 | imagePicker.allowsEditing = NO; 54 | [self presentViewController:imagePicker animated:YES completion:nil]; 55 | } 56 | 57 | #pragma mark - UIImagePickerControllerDelegate 58 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary *)editingInfo { 59 | 60 | [picker dismissViewControllerAnimated:YES completion:^{ 61 | StoryMakeImageEditorViewController *storyMakerVc = [[StoryMakeImageEditorViewController alloc] initWithImage:image]; 62 | [self presentViewController:storyMakerVc animated:YES completion:nil]; 63 | }]; 64 | } 65 | 66 | - (void)didReceiveMemoryWarning { 67 | [super didReceiveMemoryWarning]; 68 | // Dispose of any resources that can be recreated. 69 | } 70 | 71 | /* 72 | #pragma mark - Navigation 73 | 74 | // In a storyboard-based application, you will often want to do a little preparation before navigation 75 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 76 | // Get the new view controller using [segue destinationViewController]. 77 | // Pass the selected object to the new view controller. 78 | } 79 | */ 80 | 81 | @end 82 | 83 | -------------------------------------------------------------------------------- /Demo/Demo/bgStory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/Demo/Demo/bgStory.jpg -------------------------------------------------------------------------------- /Demo/Demo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |
8 | 9 | ## WHStoryMaker 10 | iOS 搭建美图——**贴纸,涂鸦,文字,滤镜** 11 | 12 | ![StoryMaker.gif](./ReadmeResource/show.gif) 13 | 14 | 小姐姐有没有很好看!是不是该点一波Star!(无耻,滚粗。。)( ̄ε(# ̄)☆╰╮o( ̄皿 ̄///) 15 | 16 | 目前美图有四个功能: 17 | 18 | **贴纸 | 涂鸦 | 文字 | 滤镜** 19 | 20 | 21 | 22 | ## WHStoryMaker接入说明: 23 | #### 1.引用头文件 24 | 25 | ```objective-c 26 | #import "WHStoryMakerHeader.h" 27 | ``` 28 | 29 | #### 2.初始化 30 | 31 | ```objective-c 32 | StoryMakeImageEditorViewController *storyMakerVc = [[StoryMakeImageEditorViewController alloc] initWithImage:image]; 33 | [self presentViewController:storyMakerVc animated:YES completion:nil]; 34 | ``` 35 | 在初始化的时候传入 **Image**。 36 | 37 | ## License 38 | 39 | WHStoryMaker is released under the MIT license. See LICENSE for details. 40 | -------------------------------------------------------------------------------- /ReadmeResource/introduce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/ReadmeResource/introduce.png -------------------------------------------------------------------------------- /ReadmeResource/license.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/ReadmeResource/license.png -------------------------------------------------------------------------------- /ReadmeResource/platform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/ReadmeResource/platform.png -------------------------------------------------------------------------------- /ReadmeResource/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/ReadmeResource/screenshot.jpg -------------------------------------------------------------------------------- /ReadmeResource/show.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/ReadmeResource/show.gif -------------------------------------------------------------------------------- /ReadmeResource/support.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/ReadmeResource/support.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_close.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_close@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_close@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_close.imageset/story maker_close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_close.imageset/story maker_close@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_close.imageset/story maker_close@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_close.imageset/story maker_close@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontborder.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_fontborder@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_fontborder@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontborder.imageset/story maker_fontborder@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontborder.imageset/story maker_fontborder@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontborder.imageset/story maker_fontborder@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontborder.imageset/story maker_fontborder@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontsize.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_fontsize@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_fontsize@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontsize.imageset/story maker_fontsize@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontsize.imageset/story maker_fontsize@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontsize.imageset/story maker_fontsize@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_fontsize.imageset/story maker_fontsize@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_next.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_next@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_next@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_next.imageset/story maker_next@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_next.imageset/story maker_next@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_next.imageset/story maker_next@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_next.imageset/story maker_next@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_filter.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_tab_filter@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_tab_filter@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_filter.imageset/story maker_tab_filter@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_filter.imageset/story maker_tab_filter@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_filter.imageset/story maker_tab_filter@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_filter.imageset/story maker_tab_filter@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_scrawl.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_tab_scrawl@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_tab_scrawl@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_scrawl.imageset/story maker_tab_scrawl@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_scrawl.imageset/story maker_tab_scrawl@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_scrawl.imageset/story maker_tab_scrawl@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_scrawl.imageset/story maker_tab_scrawl@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_sticker.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_tab_sticker@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_tab_sticker@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_sticker.imageset/story maker_tab_sticker@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_sticker.imageset/story maker_tab_sticker@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_sticker.imageset/story maker_tab_sticker@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_sticker.imageset/story maker_tab_sticker@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_type.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "story maker_tab_type@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "story maker_tab_type@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_type.imageset/story maker_tab_type@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_type.imageset/story maker_tab_type@2x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_type.imageset/story maker_tab_type@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tab_type.imageset/story maker_tab_type@3x.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi0.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi0.imageset/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi0.imageset/img.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi1.imageset/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi1.imageset/img.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi2.imageset/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi2.imageset/img.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi3.imageset/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi3.imageset/img.png -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi4.imageset/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whbalzac/WHStoryMaker/e8098878385d799ef0c0d6e957b720d7fa5f1b6b/WHStoryMaker/Resource/StoryMaker.xcassets/story_maker_tiezhi4.imageset/img.png -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/StoryMakeImageEditorViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeImageEditorViewController.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StoryMakeImageEditorViewController : UIViewController 12 | 13 | - (instancetype)initWithImage:(UIImage *)image; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Draw/LSDrawView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSDrawView.h 3 | // LSDrawTest 4 | // 5 | // Created by linyoulu on 2017/2/7. 6 | // Copyright © 2017年 linyoulu. All rights reserved. 7 | // 8 | 9 | 10 | 11 | /* 12 | 这个demo主要是参考了下面两个项目 13 | 14 | https://github.com/WillieWu/HBDrawingBoardDemo 15 | 16 | https://github.com/Nicejinux/NXDrawKit 17 | 18 | 也针对这两个demo做了相应的优化 19 | 20 | 21 | 结构:由上至下 22 | 23 | 1、最上层的UIView(LSCanvas) 24 | 使用CAShapeLayer,提高绘制时的效率 25 | 26 | 2、第二层的UIImageview是用来合成LSCanvas用的 27 | 28 | 这样画很多次的时候,也不会占用很高的cpu 29 | 30 | 3、第三层是UIImageview,是用来放背景图的 31 | 32 | ps: 33 | 没使用drawrect 34 | 35 | 关于录制脚本: 36 | 1、//linyl 标记的代码都是跟录制脚本和绘制脚本相关 37 | 2、录制后需要重新跑程序,因为这只是个demo 38 | 39 | 还需要优化的地方: 40 | 1、当前的记录方式是用归档的方式,每次有动作(撤销,重做,保存,清空)和每次的touchsend 41 | 后,都会记录成一个LSDrawPackage对象,如果想使用socket时,这里可以改为每0.5秒一个LSDrawPackage对象 42 | ,也就是说,每个LSDrawPackage对象都是一段时间内的绘制和操作。 43 | 44 | 2、线程处理 45 | demo中使用的是performselector的方式,这里还需要优化。 46 | 47 | 3、当前的绘制端和显示端公用了很多的内部结构 48 | 49 | */ 50 | 51 | #import 52 | 53 | #define MAX_UNDO_COUNT 10 54 | 55 | #define LSDEF_BRUSH_COLOR [UIColor colorWithRed:255 green:0 blue:0 alpha:1.0] 56 | 57 | #define LSDEF_BRUSH_WIDTH 3 58 | 59 | #define LSDEF_BRUSH_SHAPE LSShapeCurve 60 | 61 | //画笔形状 62 | typedef NS_ENUM(NSInteger, LSShapeType) 63 | { 64 | LSShapeCurve = 0,//曲线(默认) 65 | LSShapeLine,//直线 66 | LSShapeEllipse,//椭圆 67 | LSShapeRect,//矩形 68 | 69 | }; 70 | ///////////////////////////////////////////////////////////////////// 71 | 72 | //封装的画笔类 73 | @interface LSBrush: NSObject 74 | 75 | //画笔颜色 76 | @property (nonatomic, strong) UIColor *brushColor; 77 | 78 | //画笔宽度 79 | @property (nonatomic, assign) NSInteger brushWidth; 80 | 81 | //是否是橡皮擦 82 | @property (nonatomic, assign) BOOL isEraser; 83 | 84 | //形状 85 | @property (nonatomic, assign) LSShapeType shapeType; 86 | 87 | //路径 88 | @property (nonatomic, strong) UIBezierPath *bezierPath; 89 | 90 | //起点 91 | @property (nonatomic, assign) CGPoint beginPoint; 92 | //终点 93 | @property (nonatomic, assign) CGPoint endPoint; 94 | 95 | @end 96 | 97 | //////////////////////////////////////////////////////////////////// 98 | 99 | 100 | 101 | @interface LSCanvas : UIView 102 | 103 | - (void)setBrush:(LSBrush *)brush; 104 | 105 | @end 106 | ///////////////////////////////////////////////////////////////////// 107 | 108 | @interface LSDrawView : UIView 109 | 110 | //颜色 111 | @property (strong, nonatomic) UIColor *brushColor; 112 | //是否是橡皮擦 113 | @property (assign, nonatomic) BOOL isEraser; 114 | //宽度 115 | @property (assign, nonatomic) NSInteger brushWidth; 116 | //形状 117 | @property (assign, nonatomic) LSShapeType shapeType; 118 | //背景图 119 | @property (assign, nonatomic) UIImage *backgroundImage; 120 | 121 | @property (assign, nonatomic) BOOL isIgnoreTouch; 122 | 123 | //撤销 124 | - (void)unDo; 125 | //重做 126 | - (void)reDo; 127 | //保存到相册 128 | - (void)save; 129 | //清除绘制 130 | - (void)clean; 131 | 132 | 133 | //录制脚本 134 | - (void)testRecToFile; 135 | //绘制脚本 136 | - (void)testPlayFromFile; 137 | 138 | // StoryMake 139 | - (BOOL)isDrawBoardEmpty; 140 | - (UIImage *)getDrawBoardImage; 141 | 142 | @end 143 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Draw/YYModel/LJBaseModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LJBaseModel.h 3 | // Pinaster 4 | // 5 | // Created by LJ_Keith on 16/12/8. 6 | // Copyright © 2016年 linyoulu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface LJBaseModel : NSObject 13 | 14 | -(void)encodeWithCoder:(NSCoder *)aCoder; 15 | 16 | -(id)initWithCoder:(NSCoder *)aDecoder; 17 | 18 | -(id)copyWithZone:(NSZone *)zone; 19 | 20 | -(NSUInteger)hash; 21 | 22 | -(BOOL)isEqual:(id)object; 23 | 24 | 25 | @end 26 | 27 | @interface LSDrawModel : LJBaseModel 28 | 29 | @property (nonatomic, assign) NSInteger modelType; 30 | 31 | @end 32 | 33 | 34 | 35 | @interface LSPointModel : LSDrawModel 36 | 37 | @property (nonatomic, assign) CGFloat xPoint; 38 | 39 | @property (nonatomic, assign) CGFloat yPoint; 40 | 41 | @property (nonatomic, assign) double timeOffset; 42 | 43 | @end 44 | 45 | 46 | @interface LSBrushModel : LSDrawModel 47 | 48 | @property (nonatomic, copy) UIColor *brushColor; 49 | 50 | @property (nonatomic, assign) CGFloat brushWidth; 51 | 52 | @property (nonatomic, assign) NSInteger shapeType; 53 | 54 | @property (nonatomic, assign) BOOL isEraser; 55 | 56 | @property (nonatomic, copy) LSPointModel *beginPoint; 57 | 58 | @property (nonatomic, copy) LSPointModel *endPoint; 59 | 60 | @end 61 | 62 | typedef NS_ENUM(NSInteger, LSDrawAction) 63 | { 64 | LSDrawActionUnKnown = 1, 65 | LSDrawActionUndo, 66 | LSDrawActionRedo, 67 | LSDrawActionSave, 68 | LSDrawActionClean, 69 | LSDrawActionOther, 70 | }; 71 | 72 | @interface LSActionModel : LSDrawModel 73 | 74 | @property (nonatomic, assign) LSDrawAction ActionType; 75 | 76 | @end 77 | 78 | 79 | 80 | 81 | @interface LSDrawPackage : LJBaseModel 82 | 83 | @property (nonatomic, strong) NSMutableArray *pointOrBrushArray; 84 | 85 | @end 86 | 87 | 88 | @interface LSDrawFile : LJBaseModel 89 | 90 | @property (nonatomic, strong) NSMutableArray *packageArray; 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Draw/YYModel/LJBaseModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LJBaseModel.m 3 | // Pinaster 4 | // 5 | // Created by LJ_Keith on 16/12/8. 6 | // Copyright © 2016年 linyoulu. All rights reserved. 7 | // 8 | 9 | #import "LJBaseModel.h" 10 | #import "YYModel.h" 11 | 12 | 13 | @implementation LJBaseModel 14 | 15 | -(void)encodeWithCoder:(NSCoder *)aCoder{ 16 | 17 | [self yy_modelEncodeWithCoder:aCoder]; 18 | 19 | } 20 | 21 | -(id)initWithCoder:(NSCoder *)aDecoder{ 22 | 23 | self = [super init]; 24 | return [self yy_modelInitWithCoder:aDecoder]; 25 | 26 | } 27 | 28 | -(id)copyWithZone:(NSZone *)zone{ 29 | 30 | return [self yy_modelCopy]; 31 | 32 | } 33 | -(NSUInteger)hash{ 34 | 35 | return [self yy_modelHash]; 36 | 37 | } 38 | 39 | -(BOOL)isEqual:(id)object{ 40 | 41 | return [self yy_modelIsEqual:object]; 42 | 43 | } 44 | //避开关键字 45 | + (NSDictionary *)modelCustomPropertyMapper { 46 | return @{@"Id" : @"id", 47 | @"Description" : @"description", 48 | }; 49 | } 50 | 51 | @end 52 | 53 | @implementation LSDrawModel 54 | 55 | 56 | @end 57 | 58 | @implementation LSPointModel 59 | 60 | 61 | @end 62 | 63 | @implementation LSBrushModel 64 | 65 | 66 | @end 67 | 68 | @implementation LSActionModel 69 | 70 | 71 | @end 72 | 73 | @implementation LSDrawPackage 74 | 75 | 76 | @end 77 | 78 | @implementation LSDrawFile 79 | 80 | 81 | @end 82 | 83 | 84 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Draw/YYModel/YYClassInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYClassInfo.h 3 | // YYModel 4 | // 5 | // Created by ibireme on 15/5/9. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | #import 14 | 15 | NS_ASSUME_NONNULL_BEGIN 16 | 17 | /** 18 | Type encoding's type. 19 | */ 20 | typedef NS_OPTIONS(NSUInteger, YYEncodingType) { 21 | YYEncodingTypeMask = 0xFF, ///< mask of type value 22 | YYEncodingTypeUnknown = 0, ///< unknown 23 | YYEncodingTypeVoid = 1, ///< void 24 | YYEncodingTypeBool = 2, ///< bool 25 | YYEncodingTypeInt8 = 3, ///< char / BOOL 26 | YYEncodingTypeUInt8 = 4, ///< unsigned char 27 | YYEncodingTypeInt16 = 5, ///< short 28 | YYEncodingTypeUInt16 = 6, ///< unsigned short 29 | YYEncodingTypeInt32 = 7, ///< int 30 | YYEncodingTypeUInt32 = 8, ///< unsigned int 31 | YYEncodingTypeInt64 = 9, ///< long long 32 | YYEncodingTypeUInt64 = 10, ///< unsigned long long 33 | YYEncodingTypeFloat = 11, ///< float 34 | YYEncodingTypeDouble = 12, ///< double 35 | YYEncodingTypeLongDouble = 13, ///< long double 36 | YYEncodingTypeObject = 14, ///< id 37 | YYEncodingTypeClass = 15, ///< Class 38 | YYEncodingTypeSEL = 16, ///< SEL 39 | YYEncodingTypeBlock = 17, ///< block 40 | YYEncodingTypePointer = 18, ///< void* 41 | YYEncodingTypeStruct = 19, ///< struct 42 | YYEncodingTypeUnion = 20, ///< union 43 | YYEncodingTypeCString = 21, ///< char* 44 | YYEncodingTypeCArray = 22, ///< char[10] (for example) 45 | 46 | YYEncodingTypeQualifierMask = 0xFF00, ///< mask of qualifier 47 | YYEncodingTypeQualifierConst = 1 << 8, ///< const 48 | YYEncodingTypeQualifierIn = 1 << 9, ///< in 49 | YYEncodingTypeQualifierInout = 1 << 10, ///< inout 50 | YYEncodingTypeQualifierOut = 1 << 11, ///< out 51 | YYEncodingTypeQualifierBycopy = 1 << 12, ///< bycopy 52 | YYEncodingTypeQualifierByref = 1 << 13, ///< byref 53 | YYEncodingTypeQualifierOneway = 1 << 14, ///< oneway 54 | 55 | YYEncodingTypePropertyMask = 0xFF0000, ///< mask of property 56 | YYEncodingTypePropertyReadonly = 1 << 16, ///< readonly 57 | YYEncodingTypePropertyCopy = 1 << 17, ///< copy 58 | YYEncodingTypePropertyRetain = 1 << 18, ///< retain 59 | YYEncodingTypePropertyNonatomic = 1 << 19, ///< nonatomic 60 | YYEncodingTypePropertyWeak = 1 << 20, ///< weak 61 | YYEncodingTypePropertyCustomGetter = 1 << 21, ///< getter= 62 | YYEncodingTypePropertyCustomSetter = 1 << 22, ///< setter= 63 | YYEncodingTypePropertyDynamic = 1 << 23, ///< @dynamic 64 | }; 65 | 66 | /** 67 | Get the type from a Type-Encoding string. 68 | 69 | @discussion See also: 70 | https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html 71 | https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html 72 | 73 | @param typeEncoding A Type-Encoding string. 74 | @return The encoding type. 75 | */ 76 | YYEncodingType YYEncodingGetType(const char *typeEncoding); 77 | 78 | 79 | /** 80 | Instance variable information. 81 | */ 82 | @interface YYClassIvarInfo : NSObject 83 | @property (nonatomic, assign, readonly) Ivar ivar; ///< ivar opaque struct 84 | @property (nonatomic, strong, readonly) NSString *name; ///< Ivar's name 85 | @property (nonatomic, assign, readonly) ptrdiff_t offset; ///< Ivar's offset 86 | @property (nonatomic, strong, readonly) NSString *typeEncoding; ///< Ivar's type encoding 87 | @property (nonatomic, assign, readonly) YYEncodingType type; ///< Ivar's type 88 | 89 | /** 90 | Creates and returns an ivar info object. 91 | 92 | @param ivar ivar opaque struct 93 | @return A new object, or nil if an error occurs. 94 | */ 95 | - (instancetype)initWithIvar:(Ivar)ivar; 96 | @end 97 | 98 | 99 | /** 100 | Method information. 101 | */ 102 | @interface YYClassMethodInfo : NSObject 103 | @property (nonatomic, assign, readonly) Method method; ///< method opaque struct 104 | @property (nonatomic, strong, readonly) NSString *name; ///< method name 105 | @property (nonatomic, assign, readonly) SEL sel; ///< method's selector 106 | @property (nonatomic, assign, readonly) IMP imp; ///< method's implementation 107 | @property (nonatomic, strong, readonly) NSString *typeEncoding; ///< method's parameter and return types 108 | @property (nonatomic, strong, readonly) NSString *returnTypeEncoding; ///< return value's type 109 | @property (nullable, nonatomic, strong, readonly) NSArray *argumentTypeEncodings; ///< array of arguments' type 110 | 111 | /** 112 | Creates and returns a method info object. 113 | 114 | @param method method opaque struct 115 | @return A new object, or nil if an error occurs. 116 | */ 117 | - (instancetype)initWithMethod:(Method)method; 118 | @end 119 | 120 | 121 | /** 122 | Property information. 123 | */ 124 | @interface YYClassPropertyInfo : NSObject 125 | @property (nonatomic, assign, readonly) objc_property_t property; ///< property's opaque struct 126 | @property (nonatomic, strong, readonly) NSString *name; ///< property's name 127 | @property (nonatomic, assign, readonly) YYEncodingType type; ///< property's type 128 | @property (nonatomic, strong, readonly) NSString *typeEncoding; ///< property's encoding value 129 | @property (nonatomic, strong, readonly) NSString *ivarName; ///< property's ivar name 130 | @property (nullable, nonatomic, assign, readonly) Class cls; ///< may be nil 131 | @property (nullable, nonatomic, strong, readonly) NSArray *protocols; ///< may nil 132 | @property (nonatomic, assign, readonly) SEL getter; ///< getter (nonnull) 133 | @property (nonatomic, assign, readonly) SEL setter; ///< setter (nonnull) 134 | 135 | /** 136 | Creates and returns a property info object. 137 | 138 | @param property property opaque struct 139 | @return A new object, or nil if an error occurs. 140 | */ 141 | - (instancetype)initWithProperty:(objc_property_t)property; 142 | @end 143 | 144 | 145 | /** 146 | Class information for a class. 147 | */ 148 | @interface YYClassInfo : NSObject 149 | @property (nonatomic, assign, readonly) Class cls; ///< class object 150 | @property (nullable, nonatomic, assign, readonly) Class superCls; ///< super class object 151 | @property (nullable, nonatomic, assign, readonly) Class metaCls; ///< class's meta class object 152 | @property (nonatomic, readonly) BOOL isMeta; ///< whether this class is meta class 153 | @property (nonatomic, strong, readonly) NSString *name; ///< class name 154 | @property (nullable, nonatomic, strong, readonly) YYClassInfo *superClassInfo; ///< super class's class info 155 | @property (nullable, nonatomic, strong, readonly) NSDictionary *ivarInfos; ///< ivars 156 | @property (nullable, nonatomic, strong, readonly) NSDictionary *methodInfos; ///< methods 157 | @property (nullable, nonatomic, strong, readonly) NSDictionary *propertyInfos; ///< properties 158 | 159 | /** 160 | If the class is changed (for example: you add a method to this class with 161 | 'class_addMethod()'), you should call this method to refresh the class info cache. 162 | 163 | After called this method, `needUpdate` will returns `YES`, and you should call 164 | 'classInfoWithClass' or 'classInfoWithClassName' to get the updated class info. 165 | */ 166 | - (void)setNeedUpdate; 167 | 168 | /** 169 | If this method returns `YES`, you should stop using this instance and call 170 | `classInfoWithClass` or `classInfoWithClassName` to get the updated class info. 171 | 172 | @return Whether this class info need update. 173 | */ 174 | - (BOOL)needUpdate; 175 | 176 | /** 177 | Get the class info of a specified Class. 178 | 179 | @discussion This method will cache the class info and super-class info 180 | at the first access to the Class. This method is thread-safe. 181 | 182 | @param cls A class. 183 | @return A class info, or nil if an error occurs. 184 | */ 185 | + (nullable instancetype)classInfoWithClass:(Class)cls; 186 | 187 | /** 188 | Get the class info of a specified Class. 189 | 190 | @discussion This method will cache the class info and super-class info 191 | at the first access to the Class. This method is thread-safe. 192 | 193 | @param className A class name. 194 | @return A class info, or nil if an error occurs. 195 | */ 196 | + (nullable instancetype)classInfoWithClassName:(NSString *)className; 197 | 198 | @end 199 | 200 | NS_ASSUME_NONNULL_END 201 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Draw/YYModel/YYModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYModel.h 3 | // YYModel 4 | // 5 | // Created by ibireme on 15/5/10. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | FOUNDATION_EXPORT double YYModelVersionNumber; 16 | FOUNDATION_EXPORT const unsigned char YYModelVersionString[]; 17 | #import 18 | #import 19 | #else 20 | #import "NSObject+YYModel.h" 21 | #import "YYClassInfo.h" 22 | #endif 23 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Filter/Helper/ColorMatrix.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // pictureProcess 4 | // 5 | // Created by Ibokan on 12-9-7. 6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | //LOMO 10 | const float colormatrix_lomo[] = { 11 | 1.7f, 0.1f, 0.1f, 0, -73.1f, 12 | 0, 1.7f, 0.1f, 0, -73.1f, 13 | 0, 0.1f, 1.6f, 0, -73.1f, 14 | 0, 0, 0, 1.0f, 0 }; 15 | 16 | //黑白 17 | const float colormatrix_heibai[] = { 18 | 0.8f, 1.6f, 0.2f, 0, -163.9f, 19 | 0.8f, 1.6f, 0.2f, 0, -163.9f, 20 | 0.8f, 1.6f, 0.2f, 0, -163.9f, 21 | 0, 0, 0, 1.0f, 0 }; 22 | //复古 23 | const float colormatrix_huajiu[] = { 24 | 0.2f,0.5f, 0.1f, 0, 40.8f, 25 | 0.2f, 0.5f, 0.1f, 0, 40.8f, 26 | 0.2f,0.5f, 0.1f, 0, 40.8f, 27 | 0, 0, 0, 1, 0 }; 28 | 29 | //哥特 30 | const float colormatrix_gete[] = { 31 | 1.9f,-0.3f, -0.2f, 0,-87.0f, 32 | -0.2f, 1.7f, -0.1f, 0, -87.0f, 33 | -0.1f,-0.6f, 2.0f, 0, -87.0f, 34 | 0, 0, 0, 1.0f, 0 }; 35 | 36 | //锐化 37 | const float colormatrix_ruise[] = { 38 | 4.8f,-1.0f, -0.1f, 0,-388.4f, 39 | -0.5f,4.4f, -0.1f, 0,-388.4f, 40 | -0.5f,-1.0f, 5.2f, 0,-388.4f, 41 | 0, 0, 0, 1.0f, 0 }; 42 | 43 | 44 | //淡雅 45 | const float colormatrix_danya[] = { 46 | 0.6f,0.3f, 0.1f, 0,73.3f, 47 | 0.2f,0.7f, 0.1f, 0,73.3f, 48 | 0.2f,0.3f, 0.4f, 0,73.3f, 49 | 0, 0, 0, 1.0f, 0 }; 50 | 51 | //酒红 52 | const float colormatrix_jiuhong[] = { 53 | 1.2f,0.0f, 0.0f, 0.0f,0.0f, 54 | 0.0f,0.9f, 0.0f, 0.0f,0.0f, 55 | 0.0f,0.0f, 0.8f, 0.0f,0.0f, 56 | 0, 0, 0, 1.0f, 0 }; 57 | 58 | //清宁 59 | const float colormatrix_qingning[] = { 60 | 0.9f, 0, 0, 0, 0, 61 | 0, 1.1f,0, 0, 0, 62 | 0, 0, 0.9f, 0, 0, 63 | 0, 0, 0, 1.0f, 0 }; 64 | 65 | //浪漫 66 | const float colormatrix_langman[] = { 67 | 0.9f, 0, 0, 0, 63.0f, 68 | 0, 0.9f,0, 0, 63.0f, 69 | 0, 0, 0.9f, 0, 63.0f, 70 | 0, 0, 0, 1.0f, 0 }; 71 | 72 | //光晕 73 | const float colormatrix_guangyun[] = { 74 | 0.9f, 0, 0, 0, 64.9f, 75 | 0, 0.9f,0, 0, 64.9f, 76 | 0, 0, 0.9f, 0, 64.9f, 77 | 0, 0, 0, 1.0f, 0 }; 78 | 79 | //蓝调 80 | const float colormatrix_landiao[] = { 81 | 2.1f, -1.4f, 0.6f, 0.0f, -31.0f, 82 | -0.3f, 2.0f, -0.3f, 0.0f, -31.0f, 83 | -1.1f, -0.2f, 2.6f, 0.0f, -31.0f, 84 | 0.0f, 0.0f, 0.0f, 1.0f, 0.0f 85 | }; 86 | 87 | //梦幻 88 | const float colormatrix_menghuan[] = { 89 | 0.8f, 0.3f, 0.1f, 0.0f, 46.5f, 90 | 0.1f, 0.9f, 0.0f, 0.0f, 46.5f, 91 | 0.1f, 0.3f, 0.7f, 0.0f, 46.5f, 92 | 0.0f, 0.0f, 0.0f, 1.0f, 0.0f 93 | }; 94 | 95 | //夜色 96 | const float colormatrix_yese[] = { 97 | 1.0f, 0.0f, 0.0f, 0.0f, -66.6f, 98 | 0.0f, 1.1f, 0.0f, 0.0f, -66.6f, 99 | 0.0f, 0.0f, 1.0f, 0.0f, -66.6f, 100 | 0.0f, 0.0f, 0.0f, 1.0f, 0.0f 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Filter/Helper/ImageUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // pictureProcess 4 | // 5 | // Created by Ibokan on 12-9-7. 6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface ImageUtil : NSObject 14 | 15 | + (UIImage *)imageWithImage:(UIImage*)inImage withColorMatrix:(const float*)f; 16 | 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Filter/Helper/ImageUtil.m: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // pictureProcess 4 | // 5 | // Created by Ibokan on 12-9-7. 6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "ImageUtil.h" 10 | 11 | @implementation ImageUtil 12 | 13 | static CGContextRef CreateRGBABitmapContext (CGImageRef inImage)// 返回一个使用RGBA通道的位图上下文 14 | { 15 | CGContextRef context = NULL; 16 | CGColorSpaceRef colorSpace; 17 | void *bitmapData; //内存空间的指针,该内存空间的大小等于图像使用RGB通道所占用的字节数。 18 | int bitmapByteCount; 19 | int bitmapBytesPerRow; 20 | 21 | size_t pixelsWide = CGImageGetWidth(inImage); //获取横向的像素点的个数 22 | size_t pixelsHigh = CGImageGetHeight(inImage); //纵向 23 | 24 | bitmapBytesPerRow = (int)(pixelsWide * 4); //每一行的像素点占用的字节数,每个像素点的ARGB四个通道各占8个bit(0-255)的空间 25 | bitmapByteCount = (int)(bitmapBytesPerRow * pixelsHigh); //计算整张图占用的字节数 26 | 27 | colorSpace = CGColorSpaceCreateDeviceRGB();//创建依赖于设备的RGB通道 28 | 29 | bitmapData = malloc(bitmapByteCount); //分配足够容纳图片字节数的内存空间 30 | 31 | context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); 32 | //创建CoreGraphic的图形上下文,该上下文描述了bitmaData指向的内存空间需要绘制的图像的一些绘制参数 33 | 34 | CGColorSpaceRelease( colorSpace ); 35 | //Core Foundation中通过含有Create、Alloc的方法名字创建的指针,需要使用CFRelease()函数释放 36 | 37 | return context; 38 | } 39 | 40 | static unsigned char *RequestImagePixelData(UIImage *inImage) 41 | // 返回一个指针,该指针指向一个数组,数组中的每四个元素都是图像上的一个像素点的RGBA的数值(0-255),用无符号的char是因为它正好的取值范围就是0-255 42 | { 43 | CGImageRef img = [inImage CGImage]; 44 | CGSize size = [inImage size]; 45 | 46 | CGContextRef cgctx = CreateRGBABitmapContext(img); //使用上面的函数创建上下文 47 | 48 | CGRect rect = {{0,0},{size.width * inImage.scale, size.height * inImage.scale}}; 49 | 50 | CGContextDrawImage(cgctx, rect, img); //将目标图像绘制到指定的上下文,实际为上下文内的bitmapData。 51 | unsigned char *data = CGBitmapContextGetData (cgctx); 52 | 53 | CGContextRelease(cgctx);//释放上面的函数创建的上下文 54 | return data; 55 | } 56 | 57 | static void changeRGBA(int *red,int *green,int *blue,int *alpha, const float* f)//修改RGB的值 58 | { 59 | int redV = *red; 60 | int greenV = *green; 61 | int blueV = *blue; 62 | int alphaV = *alpha; 63 | 64 | *red = f[0] * redV + f[1] * greenV + f[2] * blueV + f[3] * alphaV + f[4]; 65 | *green = f[0+5] * redV + f[1+5] * greenV + f[2+5] * blueV + f[3+5] * alphaV + f[4+5]; 66 | *blue = f[0+5*2] * redV + f[1+5*2] * greenV + f[2+5*2] * blueV + f[3+5*2] * alphaV + f[4+5*2]; 67 | *alpha = f[0+5*3] * redV + f[1+5*3] * greenV + f[2+5*3] * blueV + f[3+5*3] * alphaV + f[4+5*3]; 68 | 69 | if (*red > 255) 70 | { 71 | *red = 255; 72 | } 73 | if(*red < 0) 74 | { 75 | *red = 0; 76 | } 77 | if (*green > 255) 78 | { 79 | *green = 255; 80 | } 81 | if (*green < 0) 82 | { 83 | *green = 0; 84 | } 85 | if (*blue > 255) 86 | { 87 | *blue = 255; 88 | } 89 | if (*blue < 0) 90 | { 91 | *blue = 0; 92 | } 93 | if (*alpha > 255) 94 | { 95 | *alpha = 255; 96 | } 97 | if (*alpha < 0) 98 | { 99 | *alpha = 0; 100 | } 101 | } 102 | 103 | + (UIImage*)imageWithImage:(UIImage*)inImage withColorMatrix:(const float*) f 104 | { 105 | unsigned char *imgPixel = RequestImagePixelData(inImage); 106 | CGImageRef inImageRef = [inImage CGImage]; 107 | GLuint w = (GLuint)CGImageGetWidth(inImageRef); 108 | GLuint h = (GLuint)CGImageGetHeight(inImageRef); 109 | 110 | int wOff = 0; 111 | int pixOff = 0; 112 | 113 | 114 | for(GLuint y = 0;y< h;y++)//双层循环按照长宽的像素个数迭代每个像素点 115 | { 116 | pixOff = wOff; 117 | 118 | for (GLuint x = 0; x 10 | 11 | @protocol StoryMakeFilterFooterViewDelegate 12 | 13 | @optional 14 | - (void)storyMakeFilterFooterViewCloseBtnClicked; 15 | - (void)storyMakeFilterFooterViewConfirmBtnClicked:(UIImage *)drawImage; 16 | 17 | @end 18 | 19 | @interface StoryMakeFilterFooterView : UIView 20 | 21 | @property (nonatomic, weak) id delegate; 22 | 23 | - (void)updateFilterViewWithImage:(UIImage *)image; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Filter/StoryMakeFilterFooterView.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeFilterFooterView.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 11/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeFilterFooterView.h" 10 | #import "StoryMakeFooterFilterCell.h" 11 | #import "StoryMakerFontManager.h" 12 | #import "ImageUtil.h" 13 | #import "ColorMatrix.h" 14 | 15 | @interface StoryMakeFilterFooterView () 16 | 17 | @property (nonatomic, strong) UIImageView *drawImgView; 18 | @property (nonatomic, strong) UIButton *cancelBtn; 19 | @property (nonatomic, strong) UIButton *confirmBtn; 20 | 21 | @property (nonatomic, strong) UICollectionView *collectionView; 22 | @property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout; 23 | @property (nonatomic, strong) NSArray *dataArray; 24 | @property (nonatomic, strong) NSArray *filterNameArray; 25 | 26 | @end 27 | 28 | @implementation StoryMakeFilterFooterView 29 | 30 | - (instancetype)init 31 | { 32 | self = [super init]; 33 | if (self) { 34 | [self configureView]; 35 | } 36 | return self; 37 | } 38 | 39 | - (void)configureView 40 | { 41 | [self addSubview:self.drawImgView]; 42 | [self.drawImgView mas_makeConstraints:^(MASConstraintMaker *make) { 43 | make.edges.mas_equalTo(self); 44 | }]; 45 | 46 | [self addSubview:self.collectionView]; 47 | [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { 48 | make.left.right.bottom.mas_equalTo(self); 49 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(100)); 50 | }]; 51 | 52 | [self addSubview:self.cancelBtn]; 53 | [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { 54 | make.centerY.mas_equalTo(self.mas_top).offset(SCREENAPPLYHEIGHT(31)); 55 | make.left.mas_equalTo(self.mas_left).offset(SCREENAPPLYHEIGHT(10)); 56 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(48)); 57 | make.width.mas_equalTo(SCREENAPPLYHEIGHT(70)); 58 | }]; 59 | 60 | [self addSubview:self.confirmBtn]; 61 | [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) { 62 | make.centerY.mas_equalTo(self.mas_top).offset(SCREENAPPLYHEIGHT(31)); 63 | make.right.mas_equalTo(self.mas_right).offset(-SCREENAPPLYHEIGHT(6)); 64 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(48)); 65 | make.width.mas_equalTo(SCREENAPPLYHEIGHT(60)); 66 | }]; 67 | } 68 | 69 | - (void)configureData:(UIImage *)image 70 | { 71 | self.filterNameArray = [NSArray arrayWithObjects:@"Normal", @"LOMO", @"黑白", @"哥特", @"复古", @"锐化", @"淡雅", @"酒红", @"清宁", @"浪漫", @"光晕", @"蓝调", @"梦幻", @"夜色",nil]; 72 | 73 | self.dataArray = @[image, 74 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_lomo], 75 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_heibai], 76 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_huajiu], 77 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_gete], 78 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_ruise], 79 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_danya], 80 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_jiuhong], 81 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_qingning], 82 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_langman], 83 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_guangyun], 84 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_landiao], 85 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_menghuan], 86 | [ImageUtil imageWithImage:image withColorMatrix:colormatrix_yese]]; 87 | 88 | } 89 | 90 | - (void)updateFilterViewWithImage:(UIImage *)image 91 | { 92 | self.drawImgView.image = image; 93 | [self configureData:image]; 94 | [self.collectionView reloadData]; 95 | } 96 | 97 | #pragma mark - 98 | #pragma mark - UICollectionViewDataSource 99 | 100 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 101 | { 102 | return 1; 103 | } 104 | 105 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 106 | return self.dataArray.count; 107 | } 108 | 109 | - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 110 | StoryMakeFooterFilterCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[StoryMakeFooterFilterCell identifierForReuseCell] forIndexPath:indexPath]; 111 | 112 | if (indexPath.section >= self.dataArray.count) { 113 | return cell; 114 | } 115 | 116 | cell.imageView.image = self.dataArray[indexPath.row]; 117 | cell.filterNameLabel.text = self.filterNameArray[indexPath.row]; 118 | 119 | return cell; 120 | } 121 | 122 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 123 | StoryMakeFooterFilterCell *cell = (StoryMakeFooterFilterCell *)[collectionView cellForItemAtIndexPath:indexPath]; 124 | if (cell.imageView.image) { 125 | self.drawImgView.image = cell.imageView.image; 126 | } 127 | } 128 | 129 | 130 | #pragma mark - 131 | #pragma mark - Btn action 132 | 133 | - (void)cancelBtnAction 134 | { 135 | if (self.delegate && [self.delegate respondsToSelector:@selector(storyMakeFilterFooterViewCloseBtnClicked)]) { 136 | [self.delegate storyMakeFilterFooterViewCloseBtnClicked]; 137 | } 138 | } 139 | 140 | - (void)confirmBtnAction 141 | { 142 | if (self.delegate && [self.delegate respondsToSelector:@selector(storyMakeFilterFooterViewConfirmBtnClicked:)]) { 143 | [self.delegate storyMakeFilterFooterViewConfirmBtnClicked:self.drawImgView.image]; 144 | } 145 | } 146 | 147 | #pragma mark - 148 | #pragma mark - Getter 149 | 150 | - (UIImageView *)drawImgView 151 | { 152 | if (!_drawImgView) { 153 | _drawImgView = [[UIImageView alloc] init]; 154 | _drawImgView.contentMode = UIViewContentModeScaleAspectFit; 155 | _drawImgView.backgroundColor = [UIColor blackColor]; 156 | _drawImgView.userInteractionEnabled = YES; 157 | } 158 | return _drawImgView; 159 | } 160 | 161 | - (UIButton *)cancelBtn { 162 | if(!_cancelBtn) { 163 | _cancelBtn = [[UIButton alloc] init]; 164 | [_cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 165 | [_cancelBtn setTitleColor:UIColorFromRGBA(255, 255, 255, 1.0) forState:UIControlStateNormal]; 166 | _cancelBtn.titleLabel.font = [StoryMakerFontManager getFontFutura:SCREENAPPLYHEIGHT(16)]; 167 | _cancelBtn.titleLabel.textAlignment = NSTextAlignmentLeft; 168 | [_cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside]; 169 | } 170 | return _cancelBtn; 171 | } 172 | 173 | - (UIButton *)confirmBtn { 174 | if(!_confirmBtn) { 175 | _confirmBtn = [[UIButton alloc] init]; 176 | [_confirmBtn setTitle:@"Done" forState:UIControlStateNormal]; 177 | [_confirmBtn setTitleColor:UIColorFromRGBA(255, 255, 255, 1.0) forState:UIControlStateNormal]; 178 | _confirmBtn.titleLabel.font = [StoryMakerFontManager getFontFutura:SCREENAPPLYHEIGHT(16)]; 179 | _confirmBtn.titleLabel.textAlignment = NSTextAlignmentRight; 180 | [_confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:UIControlEventTouchUpInside]; 181 | } 182 | return _confirmBtn; 183 | } 184 | 185 | - (UICollectionView *)collectionView { 186 | if (!_collectionView) { 187 | _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero 188 | collectionViewLayout:self.flowLayout]; 189 | _collectionView.backgroundColor = [UIColor clearColor]; 190 | _collectionView.delegate = self; 191 | _collectionView.dataSource = self; 192 | [_collectionView registerClass:[StoryMakeFooterFilterCell class] 193 | forCellWithReuseIdentifier:[StoryMakeFooterFilterCell identifierForReuseCell]]; 194 | } 195 | 196 | return _collectionView; 197 | } 198 | 199 | -(UICollectionViewFlowLayout *)flowLayout { 200 | if (!_flowLayout) { 201 | _flowLayout = [[UICollectionViewFlowLayout alloc] init]; 202 | _flowLayout.itemSize = CGSizeMake(SCREENAPPLYSPACE(50), SCREENAPPLYSPACE(75)); 203 | _flowLayout.sectionInset = UIEdgeInsetsMake(0, SCREENAPPLYSPACE(16), SCREENAPPLYSPACE(24), SCREENAPPLYSPACE(16)); 204 | _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 205 | } 206 | 207 | return _flowLayout; 208 | } 209 | 210 | 211 | @end 212 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Filter/StoryMakeFooterFilterCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeFooterFilterCell.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 11/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StoryMakeFooterFilterCell : UICollectionViewCell 12 | 13 | @property (nonatomic, strong) UIImageView *imageView; 14 | @property (nonatomic, strong) UILabel *filterNameLabel; 15 | 16 | + (NSString *)identifierForReuseCell; 17 | @end 18 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Filter/StoryMakeFooterFilterCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeFooterFilterCell.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 11/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeFooterFilterCell.h" 10 | #import "StoryMakerFontManager.h" 11 | 12 | @implementation StoryMakeFooterFilterCell 13 | 14 | #pragma mark - Class Methods 15 | + (NSString *)identifierForReuseCell { 16 | return NSStringFromClass([self class]); 17 | } 18 | 19 | - (instancetype)initWithFrame:(CGRect)frame 20 | { 21 | if (self = [super initWithFrame:frame]) { 22 | [self configureView]; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)configureView 28 | { 29 | [self.contentView addSubview:self.imageView]; 30 | [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { 31 | make.left.right.top.mas_equalTo(self.contentView); 32 | make.height.mas_equalTo(self.imageView.mas_width); 33 | }]; 34 | 35 | [self.contentView addSubview:self.filterNameLabel]; 36 | [self.filterNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { 37 | make.bottom.left.right.mas_equalTo(self.contentView); 38 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(15)); 39 | }]; 40 | } 41 | 42 | #pragma mark - 43 | #pragma mark - Getter 44 | 45 | - (UIImageView *)imageView 46 | { 47 | if (!_imageView) { 48 | _imageView = [[UIImageView alloc] init]; 49 | _imageView.contentMode = UIViewContentModeScaleAspectFill; 50 | _imageView.layer.masksToBounds = YES; 51 | _imageView.layer.cornerRadius = SCREENAPPLYHEIGHT(25); 52 | _imageView.layer.borderWidth = 2; 53 | _imageView.layer.borderColor = [UIColor whiteColor].CGColor; 54 | } 55 | return _imageView; 56 | } 57 | 58 | - (UILabel *)filterNameLabel 59 | { 60 | if (!_filterNameLabel){ 61 | _filterNameLabel = [[UILabel alloc] init]; 62 | _filterNameLabel.textColor = [UIColor whiteColor]; 63 | _filterNameLabel.textAlignment = NSTextAlignmentCenter; 64 | _filterNameLabel.font = [StoryMakerFontManager getFontFutura:SCREENAPPLYHEIGHT(12)]; 65 | _filterNameLabel.adjustsFontSizeToFitWidth = YES; 66 | } 67 | return _filterNameLabel; 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerBaseView.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerBaseView.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class StoryMakeStickerBaseView; 12 | 13 | @protocol StoryMakeStickerBaseViewDelegate 14 | 15 | @optional 16 | - (void)storyMakeStickerBaseViewCloseBtnClicked:(StoryMakeStickerBaseView *)view; 17 | 18 | @end 19 | 20 | 21 | @interface StoryMakeStickerBaseView : UIView 22 | 23 | @property (nonatomic, weak) id delegate; 24 | 25 | @property (nonatomic, assign) BOOL isSelected; 26 | 27 | - (void)adjustSizeOfSelect:(CGFloat)scale; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerBaseView.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerBaseView.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerBaseView.h" 10 | 11 | @interface StoryMakeStickerBaseView () 12 | 13 | @property (nonatomic, strong) UIButton *closeBtn; 14 | 15 | @end 16 | 17 | @implementation StoryMakeStickerBaseView 18 | 19 | - (instancetype)init 20 | { 21 | if (self = [super init]) { 22 | self.isSelected = YES; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)layoutSubviews 28 | { 29 | self.userInteractionEnabled = YES; 30 | 31 | self.closeBtn.frame = CGRectMake(0, 0, SCREENAPPLYHEIGHT(24), SCREENAPPLYHEIGHT(24)); 32 | self.closeBtn.center = CGPointMake(CGRectGetWidth(self.frame) - SCREENAPPLYHEIGHT(12), SCREENAPPLYHEIGHT(12)); 33 | [self addSubview:self.closeBtn]; 34 | } 35 | 36 | #pragma mark - 37 | #pragma mark - Btn Action 38 | 39 | - (void)closeBtnAction 40 | { 41 | if (self.delegate && [self.delegate respondsToSelector:@selector(storyMakeStickerBaseViewCloseBtnClicked:)]) { 42 | [self.delegate storyMakeStickerBaseViewCloseBtnClicked:self]; 43 | }else{ 44 | [self removeFromSuperview]; 45 | } 46 | } 47 | 48 | #pragma mark - 49 | #pragma mark - Private method 50 | 51 | - (void)setIsSelected:(BOOL)isSelected 52 | { 53 | _isSelected = isSelected; 54 | if (isSelected) { 55 | self.closeBtn.hidden = NO; 56 | }else{ 57 | self.closeBtn.hidden = YES; 58 | } 59 | } 60 | 61 | - (void)adjustSizeOfSelect:(CGFloat)scale 62 | { 63 | self.closeBtn.transform = CGAffineTransformIdentity; 64 | } 65 | 66 | #pragma mark - 67 | #pragma mark - Getter 68 | 69 | - (UIButton *)closeBtn 70 | { 71 | if (!_closeBtn) { 72 | _closeBtn = [[UIButton alloc] init]; 73 | [_closeBtn setImage:[UIImage imageNamed:@"story_maker_close"] forState:UIControlStateNormal]; 74 | [_closeBtn setBackgroundColor:UIColorFromRGBA(0, 0, 0, 1.0)]; 75 | _closeBtn.layer.masksToBounds = YES; 76 | _closeBtn.layer.cornerRadius = SCREENAPPLYHEIGHT(12); 77 | [_closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside]; 78 | } 79 | return _closeBtn; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerFootSingleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerFootSingleViewController.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, StoryMakeStickerFootSingleType){ 12 | 13 | StoryMakeStickerFootSingleTypeIndex0 = 0, 14 | StoryMakeStickerFootSingleTypeIndex1, 15 | StoryMakeStickerFootSingleTypeIndex2, 16 | 17 | StoryMakeStickerFootSingleTypeCount, 18 | }; 19 | 20 | @protocol StoryMakeStickerFootSingleViewControllerDelegate 21 | 22 | @optional 23 | 24 | - (void)singleViewControllerDidSelectedImage:(UIImage *)image; 25 | 26 | @end 27 | 28 | @interface StoryMakeStickerFootSingleViewController : UIViewController 29 | 30 | @property (nonatomic, weak) id delegate; 31 | 32 | - (instancetype)initWithType:(StoryMakeStickerFootSingleType)type; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerFootSingleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerFootSingleViewController.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerFootSingleViewController.h" 10 | #import "StoryMakeStickerFooterCell.h" 11 | 12 | @interface StoryMakeStickerFootSingleViewController () 13 | 14 | @property (nonatomic, assign) StoryMakeStickerFootSingleType type; 15 | @property (nonatomic, strong) UICollectionView *collectionView; 16 | @property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout; 17 | @property (nonatomic, strong) NSArray *dataArray; 18 | 19 | @end 20 | 21 | @implementation StoryMakeStickerFootSingleViewController 22 | 23 | - (instancetype)initWithType:(StoryMakeStickerFootSingleType)type 24 | { 25 | if (self = [super init]) { 26 | 27 | self.type = type; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)viewDidLoad { 33 | [super viewDidLoad]; 34 | 35 | [self configureView]; 36 | } 37 | 38 | - (void)configureView 39 | { 40 | 41 | [self.view addSubview:self.collectionView]; 42 | [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { 43 | make.top.left.right.bottom.mas_equalTo(self.view); 44 | }]; 45 | } 46 | 47 | #pragma mark - 48 | #pragma mark - UICollectionViewDataSource 49 | 50 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 51 | { 52 | return 1; 53 | } 54 | 55 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 56 | return self.dataArray.count; 57 | } 58 | 59 | - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 60 | StoryMakeStickerFooterCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[StoryMakeStickerFooterCell identifierForReuseCell] forIndexPath:indexPath]; 61 | 62 | if (indexPath.section >= self.dataArray.count) { 63 | return cell; 64 | } 65 | 66 | cell.imageView.image = self.dataArray[indexPath.row]; 67 | 68 | return cell; 69 | } 70 | 71 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 72 | StoryMakeStickerFooterCell *cell = (StoryMakeStickerFooterCell *)[collectionView cellForItemAtIndexPath:indexPath]; 73 | if (cell.imageView.image && self.delegate && [self.delegate respondsToSelector:@selector(singleViewControllerDidSelectedImage:)]) 74 | { 75 | [self.delegate singleViewControllerDidSelectedImage:cell.imageView.image]; 76 | } 77 | 78 | } 79 | 80 | #pragma mark - 81 | #pragma mark - Getter 82 | 83 | - (NSArray *)dataArray 84 | { 85 | if (!_dataArray) { 86 | _dataArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"story_maker_tiezhi0"],[UIImage imageNamed:@"story_maker_tiezhi1"],[UIImage imageNamed:@"story_maker_tiezhi2"],[UIImage imageNamed:@"story_maker_tiezhi3"],[UIImage imageNamed:@"story_maker_tiezhi4"], nil]; 87 | } 88 | return _dataArray; 89 | } 90 | 91 | - (UICollectionView *)collectionView { 92 | if (!_collectionView) { 93 | _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero 94 | collectionViewLayout:self.flowLayout]; 95 | _collectionView.backgroundColor = [UIColor clearColor]; 96 | _collectionView.delegate = self; 97 | _collectionView.dataSource = self; 98 | [_collectionView registerClass:[StoryMakeStickerFooterCell class] 99 | forCellWithReuseIdentifier:[StoryMakeStickerFooterCell identifierForReuseCell]]; 100 | } 101 | 102 | return _collectionView; 103 | } 104 | 105 | -(UICollectionViewFlowLayout *)flowLayout { 106 | if (!_flowLayout) { 107 | _flowLayout = [[UICollectionViewFlowLayout alloc] init]; 108 | _flowLayout.itemSize = CGSizeMake(SCREENAPPLYSPACE(100), SCREENAPPLYSPACE(100)); 109 | _flowLayout.sectionInset = UIEdgeInsetsMake(SCREENAPPLYSPACE(4), SCREENAPPLYSPACE(18), SCREENAPPLYSPACE(4), SCREENAPPLYSPACE(18)); 110 | _flowLayout.minimumLineSpacing = SCREENAPPLYSPACE(18); 111 | } 112 | 113 | return _flowLayout; 114 | } 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerFooterCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerFooterCell.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StoryMakeStickerFooterCell : UICollectionViewCell 12 | 13 | @property (nonatomic, strong) UIImageView *imageView; 14 | 15 | + (NSString *)identifierForReuseCell; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerFooterCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerFooterCell.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerFooterCell.h" 10 | 11 | @interface StoryMakeStickerFooterCell () 12 | 13 | 14 | @end 15 | 16 | @implementation StoryMakeStickerFooterCell 17 | 18 | #pragma mark - Class Methods 19 | + (NSString *)identifierForReuseCell { 20 | return NSStringFromClass([self class]); 21 | } 22 | 23 | - (instancetype)initWithFrame:(CGRect)frame 24 | { 25 | if (self = [super initWithFrame:frame]) { 26 | [self configureView]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)configureView 32 | { 33 | [self.contentView addSubview:self.imageView]; 34 | [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { 35 | make.edges.mas_equalTo(self.contentView); 36 | }]; 37 | } 38 | 39 | #pragma mark - 40 | #pragma mark - Getter 41 | 42 | - (UIImageView *)imageView 43 | { 44 | if (!_imageView) { 45 | _imageView = [[UIImageView alloc] init]; 46 | _imageView.contentMode = UIViewContentModeScaleAspectFit; 47 | } 48 | return _imageView; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerImageView.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerBaseView.h" 10 | 11 | @interface StoryMakeStickerImageView : StoryMakeStickerBaseView 12 | 13 | @property (nonatomic, strong) UIImageView *contentImageView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerImageView.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerImageView.h" 10 | 11 | @interface StoryMakeStickerImageView () 12 | 13 | @property (nonatomic, strong) UIView *seperatoeView; 14 | 15 | @end 16 | 17 | @implementation StoryMakeStickerImageView 18 | 19 | - (void)layoutSubviews 20 | { 21 | self.seperatoeView.frame = CGRectMake(0, 0, SCREENAPPLYHEIGHT(104), SCREENAPPLYHEIGHT(104)); 22 | self.seperatoeView.center = CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2); 23 | [self addSubview:self.seperatoeView]; 24 | 25 | self.contentImageView.frame = CGRectMake(0, 0, SCREENAPPLYHEIGHT(100), SCREENAPPLYHEIGHT(100)); 26 | self.contentImageView.center = CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2); 27 | [self addSubview:self.contentImageView]; 28 | 29 | UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchImage:)]; 30 | pinchGesture.delegate = self; 31 | [self addGestureRecognizer:pinchGesture]; 32 | 33 | UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)]; 34 | rotationGesture.delegate = self; 35 | [self addGestureRecognizer:rotationGesture]; 36 | 37 | UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panImage:)]; 38 | [self addGestureRecognizer:panGesture]; 39 | 40 | [super layoutSubviews]; 41 | } 42 | 43 | #pragma mark - 44 | #pragma mark - Private method 45 | 46 | -(void)pinchImage:(UIPinchGestureRecognizer *)gesture{ 47 | 48 | if (gesture.state == UIGestureRecognizerStateChanged) { 49 | self.transform = CGAffineTransformScale(self.transform, gesture.scale, gesture.scale); 50 | gesture.scale = 1; 51 | } 52 | } 53 | 54 | -(void)rotateImage:(UIRotationGestureRecognizer *)gesture{ 55 | 56 | if (gesture.state == UIGestureRecognizerStateChanged) { 57 | self.transform = CGAffineTransformRotate(self.transform, gesture.rotation); 58 | [gesture setRotation:0]; 59 | } 60 | } 61 | 62 | - (void)panImage:(UIPanGestureRecognizer *)gesture 63 | { 64 | if (gesture.state == UIGestureRecognizerStateChanged) { 65 | CGPoint translation = [gesture translationInView:self.superview]; 66 | [self setCenter:(CGPoint){self.center.x + translation.x, self.center.y + translation.y}]; 67 | [gesture setTranslation:CGPointZero inView:self.superview]; 68 | } 69 | } 70 | 71 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 72 | { 73 | return YES; 74 | } 75 | 76 | #pragma mark - 77 | #pragma mark - Private method 78 | 79 | - (void)setIsSelected:(BOOL)isSelected 80 | { 81 | [super setIsSelected:isSelected]; 82 | if (isSelected) { 83 | self.seperatoeView.layer.borderColor = UIColorFromRGBA(255, 255, 255, 0.5).CGColor; 84 | self.seperatoeView.layer.borderWidth = 2; 85 | }else{ 86 | self.seperatoeView.layer.borderWidth = 0; 87 | } 88 | } 89 | 90 | // 91 | - (void)adjustSizeOfSelect:(CGFloat)scale 92 | { 93 | [super adjustSizeOfSelect:scale]; 94 | 95 | self.seperatoeView.layer.borderColor = UIColorFromRGBA(255, 255, 255, 0.5).CGColor; 96 | self.seperatoeView.layer.borderWidth = 2; 97 | } 98 | 99 | #pragma mark - 100 | #pragma mark - Getter 101 | 102 | - (UIView *)seperatoeView 103 | { 104 | if (!_seperatoeView) { 105 | _seperatoeView = [[UIView alloc] init]; 106 | _seperatoeView.layer.borderColor = UIColorFromRGBA(255, 255, 255, 0.5).CGColor; 107 | _seperatoeView.layer.borderWidth = 2; 108 | } 109 | return _seperatoeView; 110 | } 111 | 112 | - (UIImageView *)contentImageView 113 | { 114 | if (!_contentImageView) { 115 | _contentImageView = [[UIImageView alloc] init]; 116 | _contentImageView.contentMode = UIViewContentModeScaleAspectFit; 117 | } 118 | return _contentImageView; 119 | } 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerView.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol StoryMakeStickerViewDelegate 12 | @optional 13 | - (void)stickerViewDidSelectedImage:(UIImage *)image; 14 | @end 15 | 16 | @interface StoryMakeStickerView : UIView 17 | 18 | @property (nonatomic, weak) id delegate; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Sticker/StoryMakeStickerView.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerView.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerView.h" 10 | #import "StoryMakeStickerFootSingleViewController.h" 11 | #import "StoryMakerFontManager.h" 12 | 13 | @interface StoryMakeStickerView () 14 | 15 | @property (nonatomic, strong) UIView *topGestureView; 16 | @property (nonatomic, strong) UIView *maskView; 17 | @property (nonatomic, strong) UIVisualEffectView *blurEffectView; 18 | 19 | @property (nonatomic, strong) UILabel *vcTitleLabel; 20 | @property (nonatomic, assign) StoryMakeStickerFootSingleType currentIndex; 21 | @property (nonatomic, strong) StoryMakeStickerFootSingleViewController *nextViewController; 22 | @property (nonatomic, strong) NSArray *viewControllerArray; 23 | @property (nonatomic, strong) UIPageViewController *pageViewController; 24 | @property (nonatomic, strong) UIView *topView; 25 | @property (nonatomic, strong) UIPageControl *pageControl; 26 | 27 | @end 28 | 29 | @implementation StoryMakeStickerView 30 | 31 | - (instancetype)init 32 | { 33 | if (self = [super init]) { 34 | [self configureView]; 35 | 36 | } 37 | return self; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark - configure 42 | 43 | - (void)configureView 44 | { 45 | UITapGestureRecognizer *getsture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideStickerFooterView)]; 46 | self.userInteractionEnabled = YES; 47 | [self.topGestureView addGestureRecognizer:getsture]; 48 | 49 | [self addSubview:self.maskView]; 50 | [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) { 51 | make.bottom.mas_equalTo(self).offset(SCREENAPPLYHEIGHT(15)); 52 | make.left.right.mas_equalTo(self); 53 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(415)); 54 | }]; 55 | 56 | [self addSubview:self.topGestureView]; 57 | [self.topGestureView mas_makeConstraints:^(MASConstraintMaker *make) { 58 | make.bottom.mas_equalTo(self.maskView.mas_top); 59 | make.left.right.top.mas_equalTo(self); 60 | }]; 61 | 62 | [self.maskView addSubview:self.blurEffectView]; 63 | [self.blurEffectView mas_makeConstraints:^(MASConstraintMaker *make) { 64 | make.left.right.top.mas_equalTo(self.maskView); 65 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(400)); 66 | }]; 67 | 68 | [self addSubview:self.vcTitleLabel]; 69 | [self.vcTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { 70 | make.top.mas_equalTo(self.maskView).offset(SCREENAPPLYHEIGHT(14)); 71 | make.left.mas_equalTo(self.maskView).offset(SCREENAPPLYHEIGHT(20)); 72 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(22)); 73 | }]; 74 | 75 | [self addSubview:self.pageViewController.view]; 76 | [self.pageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) { 77 | make.top.mas_equalTo(self.maskView).offset(SCREENAPPLYHEIGHT(50)); 78 | make.left.right.mas_equalTo(self.maskView); 79 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(350)); 80 | }]; 81 | 82 | [self addSubview:self.topView]; 83 | [self.topView mas_makeConstraints:^(MASConstraintMaker *make) { 84 | make.centerX.mas_equalTo(self); 85 | make.top.mas_equalTo(self.blurEffectView.mas_top).offset(SCREENAPPLYHEIGHT(8)); 86 | make.width.mas_equalTo(SCREENAPPLYHEIGHT(40)); 87 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(4)); 88 | }]; 89 | 90 | [self addSubview:self.pageControl]; 91 | [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) { 92 | make.centerX.mas_equalTo(self); 93 | make.top.mas_equalTo(self.blurEffectView.mas_top).offset(SCREENAPPLYHEIGHT(22)); 94 | make.width.mas_equalTo(SCREENAPPLYHEIGHT(36)); 95 | make.height.mas_equalTo(SCREENAPPLYHEIGHT(8)); 96 | }]; 97 | 98 | } 99 | 100 | 101 | #pragma mark - 102 | #pragma mark - Private method 103 | 104 | - (void)hideStickerFooterView 105 | { 106 | [UIView animateWithDuration:0.3 107 | animations:^{ 108 | self.center = CGPointMake(self.center.x, self.center.y + SCREENAPPLYHEIGHT(667)); 109 | } completion:^(BOOL finished) { 110 | self.hidden = YES; 111 | }]; 112 | } 113 | 114 | #pragma mark - UIPageViewControllerDataSource 115 | - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController 116 | viewControllerBeforeViewController:(UIViewController *)viewController{ 117 | 118 | NSInteger index = [self.viewControllerArray indexOfObject:(StoryMakeStickerFootSingleViewController *)viewController]; 119 | if (NSNotFound == index || StoryMakeStickerFootSingleTypeIndex0 == index) { 120 | return nil; 121 | } 122 | else{ 123 | return self.viewControllerArray[index - 1]; 124 | } 125 | } 126 | 127 | - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController 128 | viewControllerAfterViewController:(UIViewController *)viewController{ 129 | 130 | NSInteger index = [self.viewControllerArray indexOfObject:(StoryMakeStickerFootSingleViewController *)viewController]; 131 | if (NSNotFound == index || StoryMakeStickerFootSingleTypeIndex2 == index) { 132 | return nil; 133 | } 134 | else{ 135 | return self.viewControllerArray[index + 1]; 136 | } 137 | } 138 | 139 | #pragma mark - UIPageViewControllerDelegate 140 | - (void)pageViewController:(UIPageViewController *)pageViewController 141 | willTransitionToViewControllers:(NSArray *)pendingViewControllers{ 142 | 143 | self.nextViewController = (StoryMakeStickerFootSingleViewController *)pendingViewControllers.firstObject; 144 | } 145 | 146 | - (void)pageViewController:(UIPageViewController *)pageViewController 147 | didFinishAnimating:(BOOL)finished 148 | previousViewControllers:(NSArray *)previousViewControllers 149 | transitionCompleted:(BOOL)completed{ 150 | 151 | if (finished) { 152 | NSInteger index = [self.viewControllerArray indexOfObject:self.nextViewController]; 153 | self.pageControl.currentPage = index; 154 | } else { 155 | self.nextViewController = (StoryMakeStickerFootSingleViewController *)previousViewControllers.firstObject; 156 | } 157 | } 158 | 159 | 160 | #pragma mark - 161 | #pragma mark - StoryMakeStickerFootSingleViewControllerDelegate 162 | - (void)singleViewControllerDidSelectedImage:(UIImage *)image 163 | { 164 | if (self.delegate && [self.delegate respondsToSelector:@selector(stickerViewDidSelectedImage:)]) { 165 | [self.delegate stickerViewDidSelectedImage:image]; 166 | } 167 | } 168 | 169 | #pragma mark - 170 | #pragma mark - Getter 171 | 172 | - (UIVisualEffectView *)blurEffectView 173 | { 174 | if (!_blurEffectView) { 175 | UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 176 | _blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 177 | } 178 | return _blurEffectView; 179 | } 180 | 181 | - (UIView *)topGestureView 182 | { 183 | if (!_topGestureView) { 184 | _topGestureView = [[UIView alloc] init]; 185 | _topGestureView.backgroundColor = [UIColor clearColor]; 186 | } 187 | return _topGestureView; 188 | } 189 | 190 | - (UIView *)maskView 191 | { 192 | if (!_maskView) { 193 | _maskView = [[UIView alloc] init]; 194 | _maskView.backgroundColor = [UIColor clearColor]; 195 | _maskView.layer.masksToBounds = YES; 196 | _maskView.layer.cornerRadius = SCREENAPPLYHEIGHT(12); 197 | } 198 | return _maskView; 199 | } 200 | 201 | - (NSArray *)viewControllerArray 202 | { 203 | if (!_viewControllerArray) { 204 | 205 | NSMutableArray *array = [NSMutableArray array]; 206 | NSInteger i; 207 | for (i = 0; i < StoryMakeStickerFootSingleTypeCount; ++i) { 208 | StoryMakeStickerFootSingleViewController *singleVC = [[StoryMakeStickerFootSingleViewController alloc] initWithType:(StoryMakeStickerFootSingleType)i]; 209 | singleVC.delegate = self; 210 | [array addObject:singleVC]; 211 | _viewControllerArray = [NSArray arrayWithArray:array]; 212 | } 213 | } 214 | 215 | return _viewControllerArray; 216 | } 217 | 218 | - (UIPageViewController *)pageViewController 219 | { 220 | if (!_pageViewController) { 221 | _pageViewController = [[UIPageViewController alloc] 222 | initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll 223 | navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; 224 | 225 | [_pageViewController setViewControllers:@[self.viewControllerArray[StoryMakeStickerFootSingleTypeIndex0]] 226 | direction:UIPageViewControllerNavigationDirectionForward 227 | animated:NO 228 | completion:nil]; 229 | 230 | _pageViewController.dataSource = self; 231 | _pageViewController.delegate = self; 232 | } 233 | 234 | return _pageViewController; 235 | } 236 | 237 | - (UIPageControl *)pageControl 238 | { 239 | if (!_pageControl) { 240 | _pageControl = [[UIPageControl alloc] init]; 241 | _pageControl.numberOfPages = StoryMakeStickerFootSingleTypeCount; 242 | _pageControl.currentPage = StoryMakeStickerFootSingleTypeIndex0; 243 | _pageControl.currentPageIndicatorTintColor = UIColorFromRGBA(255, 255, 255, 1.0); 244 | _pageControl.pageIndicatorTintColor = UIColorFromRGBA(255, 255, 255, 0.5); 245 | } 246 | return _pageControl; 247 | } 248 | 249 | - (UIView *)topView 250 | { 251 | if (!_topView) { 252 | _topView = [[UIView alloc] init]; 253 | _topView.backgroundColor = UIColorFromRGBA(255, 255, 255, 0.5); 254 | _topView.layer.masksToBounds = YES; 255 | _topView.layer.cornerRadius = SCREENAPPLYHEIGHT(2); 256 | } 257 | return _topView; 258 | } 259 | 260 | 261 | - (UILabel *)vcTitleLabel 262 | { 263 | if (!_vcTitleLabel) { 264 | _vcTitleLabel = [[UILabel alloc] init]; 265 | _vcTitleLabel.textColor = [UIColor whiteColor]; 266 | _vcTitleLabel.font = [StoryMakerFontManager getFontFutura:SCREENAPPLYHEIGHT(16)]; 267 | _vcTitleLabel.textAlignment = NSTextAlignmentLeft; 268 | _vcTitleLabel.text = @"Cartoon"; 269 | } 270 | return _vcTitleLabel; 271 | } 272 | 273 | @end 274 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/StoryMakeToolsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeToolsView.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol StoryMakeToolsViewDelegate 12 | 13 | @optional 14 | 15 | - (void)stickerBtnDidSelected; 16 | - (void)drawBtnDidSelected; 17 | - (void)writeBtnDidSelected; 18 | - (void)filterBtnDidSelected; 19 | 20 | @end 21 | 22 | 23 | @interface StoryMakeToolsView : UIView 24 | 25 | @property (nonatomic, weak) id delegate; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/StoryMakeToolsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeToolsView.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 09/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeToolsView.h" 10 | 11 | @interface StoryMakeToolsView () 12 | 13 | @property (nonatomic, strong) UIButton *stickerBtn; 14 | @property (nonatomic, strong) UIButton *drawBtn; 15 | @property (nonatomic, strong) UIButton *writeBtn; 16 | @property (nonatomic, strong) UIButton *fiterBtn; 17 | 18 | @end 19 | 20 | @implementation StoryMakeToolsView 21 | 22 | - (instancetype)init 23 | { 24 | if (self = [super init]) { 25 | [self configureView]; 26 | } 27 | return self; 28 | } 29 | 30 | #pragma mark - 31 | #pragma mark - configure 32 | 33 | - (void)configureView 34 | { 35 | [self addSubview:self.stickerBtn]; 36 | [self.stickerBtn mas_makeConstraints:^(MASConstraintMaker *make) { 37 | make.centerY.mas_equalTo(self); 38 | make.centerX.mas_equalTo(self).offset(-SCREENAPPLYHEIGHT(108)); 39 | make.height.width.mas_equalTo(SCREENAPPLYHEIGHT(40)); 40 | }]; 41 | 42 | [self addSubview:self.drawBtn]; 43 | [self.drawBtn mas_makeConstraints:^(MASConstraintMaker *make) { 44 | make.centerY.mas_equalTo(self); 45 | make.centerX.mas_equalTo(self).offset(-SCREENAPPLYHEIGHT(36)); 46 | make.height.width.mas_equalTo(SCREENAPPLYHEIGHT(40)); 47 | }]; 48 | 49 | [self addSubview:self.writeBtn]; 50 | [self.writeBtn mas_makeConstraints:^(MASConstraintMaker *make) { 51 | make.centerY.mas_equalTo(self); 52 | make.centerX.mas_equalTo(self).offset(SCREENAPPLYHEIGHT(36)); 53 | make.height.width.mas_equalTo(SCREENAPPLYHEIGHT(40)); 54 | }]; 55 | 56 | [self addSubview:self.fiterBtn]; 57 | [self.fiterBtn mas_makeConstraints:^(MASConstraintMaker *make) { 58 | make.centerY.mas_equalTo(self); 59 | make.centerX.mas_equalTo(self).offset(SCREENAPPLYHEIGHT(108)); 60 | make.height.width.mas_equalTo(SCREENAPPLYHEIGHT(40)); 61 | }]; 62 | 63 | } 64 | 65 | #pragma mark - 66 | #pragma mark - Btn Action 67 | 68 | - (void)stickerBtnAction 69 | { 70 | if (self.delegate && [self.delegate respondsToSelector:@selector(stickerBtnDidSelected)]) { 71 | [self.delegate stickerBtnDidSelected]; 72 | } 73 | } 74 | 75 | - (void)drawBtnAction 76 | { 77 | if (self.delegate && [self.delegate respondsToSelector:@selector(drawBtnDidSelected)]) { 78 | [self.delegate drawBtnDidSelected]; 79 | } 80 | } 81 | 82 | - (void)writeBtnAction 83 | { 84 | if (self.delegate && [self.delegate respondsToSelector:@selector(writeBtnDidSelected)]) { 85 | [self.delegate writeBtnDidSelected]; 86 | } 87 | } 88 | 89 | - (void)filterBtnAction 90 | { 91 | if (self.delegate && [self.delegate respondsToSelector:@selector(filterBtnDidSelected)]) { 92 | [self.delegate filterBtnDidSelected]; 93 | } 94 | } 95 | 96 | 97 | 98 | 99 | #pragma mark - 100 | #pragma mark - Getter 101 | 102 | - (UIButton *)stickerBtn 103 | { 104 | if (!_stickerBtn) { 105 | _stickerBtn = [[UIButton alloc] init]; 106 | [_stickerBtn setImage:[UIImage imageNamed:@"story_maker_tab_sticker"] forState:UIControlStateNormal]; 107 | _stickerBtn.layer.shadowColor = UIColorFromRGB(0, 0, 0).CGColor; 108 | _stickerBtn.layer.shadowOffset = CGSizeMake(0, 2); 109 | _stickerBtn.layer.shadowRadius = 2; 110 | _stickerBtn.layer.shadowOpacity = 0.3; 111 | [_stickerBtn addTarget:self action:@selector(stickerBtnAction) forControlEvents:UIControlEventTouchUpInside]; 112 | } 113 | return _stickerBtn; 114 | } 115 | 116 | - (UIButton *)drawBtn 117 | { 118 | if (!_drawBtn) { 119 | _drawBtn = [[UIButton alloc] init]; 120 | [_drawBtn setImage:[UIImage imageNamed:@"story_maker_tab_scrawl"] forState:UIControlStateNormal]; 121 | _drawBtn.layer.shadowColor = UIColorFromRGB(0, 0, 0).CGColor; 122 | _drawBtn.layer.shadowOffset = CGSizeMake(0, 2); 123 | _drawBtn.layer.shadowRadius = 2; 124 | _drawBtn.layer.shadowOpacity = 0.3; 125 | [_drawBtn addTarget:self action:@selector(drawBtnAction) forControlEvents:UIControlEventTouchUpInside]; 126 | } 127 | return _drawBtn; 128 | } 129 | 130 | - (UIButton *)writeBtn 131 | { 132 | if (!_writeBtn) { 133 | _writeBtn = [[UIButton alloc] init]; 134 | [_writeBtn setImage:[UIImage imageNamed:@"story_maker_tab_type"] forState:UIControlStateNormal]; 135 | _writeBtn.layer.shadowColor = UIColorFromRGB(0, 0, 0).CGColor; 136 | _writeBtn.layer.shadowOffset = CGSizeMake(0, 2); 137 | _writeBtn.layer.shadowRadius = 2; 138 | _writeBtn.layer.shadowOpacity = 0.3; 139 | [_writeBtn addTarget:self action:@selector(writeBtnAction) forControlEvents:UIControlEventTouchUpInside]; 140 | } 141 | return _writeBtn; 142 | } 143 | 144 | - (UIButton *)fiterBtn 145 | { 146 | if (!_fiterBtn) { 147 | _fiterBtn = [[UIButton alloc] init]; 148 | [_fiterBtn setImage:[UIImage imageNamed:@"story_maker_tab_filter"] forState:UIControlStateNormal]; 149 | _fiterBtn.layer.shadowColor = UIColorFromRGB(0, 0, 0).CGColor; 150 | _fiterBtn.layer.shadowOffset = CGSizeMake(0, 2); 151 | _fiterBtn.layer.shadowRadius = 2; 152 | _fiterBtn.layer.shadowOpacity = 0.3; 153 | [_fiterBtn addTarget:self action:@selector(filterBtnAction) forControlEvents:UIControlEventTouchUpInside]; 154 | } 155 | return _fiterBtn; 156 | } 157 | 158 | 159 | @end 160 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeSelectColorFooterView.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeSelectColorFooterView.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, StoryMakeSelectColorFooterViewType){ 12 | 13 | StoryMakeSelectColorFooterViewTypeDrawing = 0, 14 | StoryMakeSelectColorFooterViewTypeWriting 15 | }; 16 | 17 | @protocol StoryMakeSelectColorFooterViewDelegate 18 | 19 | @optional 20 | - (void)storyMakeSelectColorFooterViewCloseBtnClicked; 21 | - (void)storyMakeSelectColorFooterViewConfirmBtnClicked:(NSString *)text font:(UIFont *)font color:(UIColor *)color; 22 | - (void)storyMakeSelectColorFooterViewConfirmBtnClicked:(UIImage *)drawImage; 23 | 24 | @end 25 | 26 | @interface StoryMakeSelectColorFooterView : UIView 27 | 28 | @property (nonatomic, weak) id delegate; 29 | 30 | @property (nonatomic, assign) StoryMakeSelectColorFooterViewType type; 31 | 32 | - (void)updateColorFooterViewInMainView; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeStickerColorFootCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerColorFootCollectionViewCell.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StoryMakeStickerColorFootCollectionViewCell : UICollectionViewCell 12 | 13 | @property (nonatomic, strong) UIColor *contentColor; 14 | 15 | + (NSString *)identifierForReuseCell; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeStickerColorFootCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerColorFootCollectionViewCell.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerColorFootCollectionViewCell.h" 10 | 11 | @implementation StoryMakeStickerColorFootCollectionViewCell 12 | 13 | #pragma mark - Class Methods 14 | + (NSString *)identifierForReuseCell { 15 | return NSStringFromClass([self class]); 16 | } 17 | 18 | - (instancetype)initWithFrame:(CGRect)frame 19 | { 20 | if (self = [super initWithFrame:frame]) { 21 | [self configureView]; 22 | } 23 | return self; 24 | } 25 | 26 | - (void)configureView 27 | { 28 | self.contentView.layer.masksToBounds = YES; 29 | self.contentView.layer.cornerRadius = SCREENAPPLYHEIGHT(12); 30 | self.contentView.layer.borderColor = [UIColor whiteColor].CGColor; 31 | self.contentView.layer.borderWidth = 1.0f; 32 | } 33 | 34 | - (void)setContentColor:(UIColor *)contentColor 35 | { 36 | _contentColor = contentColor; 37 | self.contentView.backgroundColor = contentColor; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeStickerColorFootSingleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerColorFootSingleViewController.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, StoryMakeStickerColorFootSingleType){ 12 | 13 | StoryMakeStickerColorFootSingleTypeIndex0 = 0, 14 | StoryMakeStickerColorFootSingleTypeIndex1, 15 | StoryMakeStickerColorFootSingleTypeIndex2, 16 | 17 | StoryMakeStickerColorFootSingleTypeCount, 18 | }; 19 | 20 | @protocol StoryMakeStickerColorFootSingleViewControllerDelegate 21 | @optional 22 | - (void)colorFootSingleViewControllerDidSelectedColor:(UIColor *)color; 23 | @end 24 | 25 | @interface StoryMakeStickerColorFootSingleViewController : UIViewController 26 | 27 | @property (nonatomic, weak) id delegate; 28 | 29 | - (instancetype)initWithType:(StoryMakeStickerColorFootSingleType)type; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeStickerColorFootSingleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerColorFootSingleViewController.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 10/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerColorFootSingleViewController.h" 10 | #import "StoryMakeStickerColorFootCollectionViewCell.h" 11 | 12 | @interface StoryMakeStickerColorFootSingleViewController () 13 | 14 | @property (nonatomic, assign) StoryMakeStickerColorFootSingleType type; 15 | 16 | @property (nonatomic, strong) UICollectionView *collectionView; 17 | @property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout; 18 | @property (nonatomic, strong) NSArray *dataArray; 19 | 20 | @end 21 | 22 | @implementation StoryMakeStickerColorFootSingleViewController 23 | 24 | - (instancetype)initWithType:(StoryMakeStickerColorFootSingleType)type 25 | { 26 | if (self = [super init]) { 27 | self.type = type; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)viewDidLoad { 33 | [super viewDidLoad]; 34 | 35 | [self configureData]; 36 | [self configureView]; 37 | } 38 | 39 | - (void)configureView 40 | { 41 | [self.view addSubview:self.collectionView]; 42 | [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { 43 | make.top.left.right.bottom.mas_equalTo(self.view); 44 | }]; 45 | } 46 | 47 | - (void)configureData 48 | { 49 | if (self.type == StoryMakeStickerColorFootSingleTypeIndex0) { 50 | self.dataArray = [NSArray arrayWithObjects:UIColorFromRGB(255, 255, 255), 51 | UIColorFromRGB(0, 0, 0), 52 | UIColorFromRGB(51, 151, 240), 53 | UIColorFromRGB(112, 193, 80), 54 | UIColorFromRGB(253, 203, 91), 55 | UIColorFromRGB(254, 141, 53), 56 | UIColorFromRGB(236, 73, 86), 57 | UIColorFromRGB(208, 11, 106), 58 | UIColorFromRGB(164, 7, 186),nil]; 59 | 60 | }else if(self.type == StoryMakeStickerColorFootSingleTypeIndex1) { 61 | self.dataArray = [NSArray arrayWithObjects:UIColorFromRGB(237, 1, 16), 62 | UIColorFromRGB(237, 133, 142), 63 | UIColorFromRGB(255, 210, 211), 64 | UIColorFromRGB(255, 219, 181), 65 | UIColorFromRGB(255, 195, 129), 66 | UIColorFromRGB(210, 143, 68), 67 | UIColorFromRGB(154, 100, 58), 68 | UIColorFromRGB(67, 36, 37), 69 | UIColorFromRGB(27, 74, 41),nil]; 70 | 71 | }else if(self.type == StoryMakeStickerColorFootSingleTypeIndex2) { 72 | self.dataArray = [NSArray arrayWithObjects:UIColorFromRGB(38, 38, 38), 73 | UIColorFromRGB(54, 54, 54), 74 | UIColorFromRGB(85, 85, 85), 75 | UIColorFromRGB(115, 115, 115), 76 | UIColorFromRGB(153, 153, 153), 77 | UIColorFromRGB(178, 178, 178), 78 | UIColorFromRGB(199, 199, 199), 79 | UIColorFromRGB(219, 219, 219), 80 | UIColorFromRGB(239, 239, 239),nil]; 81 | 82 | }else{ 83 | self.dataArray = [NSArray arrayWithObjects:UIColorFromRGB(255, 255, 255), 84 | UIColorFromRGB(0, 0, 0), 85 | UIColorFromRGB(51, 151, 240), 86 | UIColorFromRGB(112, 193, 80), 87 | UIColorFromRGB(253, 203, 91), 88 | UIColorFromRGB(254, 141, 53), 89 | UIColorFromRGB(236, 73, 86), 90 | UIColorFromRGB(208, 11, 106), 91 | UIColorFromRGB(164, 7, 186),nil]; 92 | } 93 | } 94 | 95 | #pragma mark - 96 | #pragma mark - UICollectionViewDataSource 97 | 98 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 99 | { 100 | return 1; 101 | } 102 | 103 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 104 | return self.dataArray.count; 105 | } 106 | 107 | - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 108 | StoryMakeStickerColorFootCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[StoryMakeStickerColorFootCollectionViewCell identifierForReuseCell] forIndexPath:indexPath]; 109 | 110 | if (indexPath.section >= self.dataArray.count) { 111 | return cell; 112 | } 113 | 114 | cell.contentColor = self.dataArray[indexPath.row]; 115 | 116 | return cell; 117 | } 118 | 119 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 120 | StoryMakeStickerColorFootCollectionViewCell *cell = (StoryMakeStickerColorFootCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; 121 | if (cell.contentColor && self.delegate && [self.delegate respondsToSelector:@selector(colorFootSingleViewControllerDidSelectedColor:)]) 122 | { 123 | [self.delegate colorFootSingleViewControllerDidSelectedColor:cell.contentColor]; 124 | } 125 | } 126 | 127 | #pragma mark - 128 | #pragma mark - Getter 129 | 130 | - (UICollectionView *)collectionView { 131 | if (!_collectionView) { 132 | _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero 133 | collectionViewLayout:self.flowLayout]; 134 | _collectionView.backgroundColor = [UIColor clearColor]; 135 | _collectionView.delegate = self; 136 | _collectionView.dataSource = self; 137 | [_collectionView registerClass:[StoryMakeStickerColorFootCollectionViewCell class] 138 | forCellWithReuseIdentifier:[StoryMakeStickerColorFootCollectionViewCell identifierForReuseCell]]; 139 | } 140 | 141 | return _collectionView; 142 | } 143 | 144 | -(UICollectionViewFlowLayout *)flowLayout { 145 | if (!_flowLayout) { 146 | _flowLayout = [[UICollectionViewFlowLayout alloc] init]; 147 | _flowLayout.itemSize = CGSizeMake(SCREENAPPLYSPACE(24), SCREENAPPLYSPACE(24)); 148 | _flowLayout.sectionInset = UIEdgeInsetsMake(0,0,0,0); 149 | _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 150 | } 151 | 152 | return _flowLayout; 153 | } 154 | 155 | @end 156 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeStickerLabelView.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerLabelView.h 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 11/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerBaseView.h" 10 | 11 | @interface StoryMakeStickerLabelView : StoryMakeStickerBaseView 12 | 13 | @property (nonatomic, strong) UILabel *contentLabel; 14 | 15 | - (instancetype)initWithLabelHeight:(CGSize)labelSize; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerEditor/View/Write/StoryMakeStickerLabelView.m: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakeStickerLabelView.m 3 | // GetZSCStoryMaker 4 | // 5 | // Created by whbalzac on 11/08/2017. 6 | // Copyright © 2017 makeupopular.com. All rights reserved. 7 | // 8 | 9 | #import "StoryMakeStickerLabelView.h" 10 | 11 | @interface StoryMakeStickerLabelView () 12 | 13 | @property (nonatomic, strong) UIView *seperatoeView; 14 | 15 | @property (nonatomic, assign) CGSize labelSize; 16 | 17 | @end 18 | 19 | @implementation StoryMakeStickerLabelView 20 | 21 | - (instancetype)initWithLabelHeight:(CGSize)labelSize 22 | { 23 | self = [super init]; 24 | if (self) { 25 | self.labelSize = labelSize; 26 | } 27 | return self; 28 | } 29 | 30 | - (void)layoutSubviews 31 | { 32 | self.seperatoeView.frame = CGRectMake(0, 0, self.labelSize.width + SCREENAPPLYHEIGHT(20), self.labelSize.height + SCREENAPPLYHEIGHT(10)); 33 | self.seperatoeView.center = CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2); 34 | [self addSubview:self.seperatoeView]; 35 | 36 | self.contentLabel.frame = CGRectMake(0, 0, self.labelSize.width, self.labelSize.height); 37 | self.contentLabel.center = CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2); 38 | [self addSubview:self.contentLabel]; 39 | 40 | UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchImage:)]; 41 | pinchGesture.delegate = self; 42 | [self addGestureRecognizer:pinchGesture]; 43 | 44 | UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)]; 45 | rotationGesture.delegate = self; 46 | [self addGestureRecognizer:rotationGesture]; 47 | 48 | UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panImage:)]; 49 | [self addGestureRecognizer:panGesture]; 50 | 51 | [super layoutSubviews]; 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark - Private method 56 | 57 | -(void)pinchImage:(UIPinchGestureRecognizer *)gesture{ 58 | 59 | if (gesture.state == UIGestureRecognizerStateChanged) { 60 | self.transform = CGAffineTransformScale(self.transform, gesture.scale, gesture.scale); 61 | gesture.scale = 1; 62 | } 63 | } 64 | 65 | -(void)rotateImage:(UIRotationGestureRecognizer *)gesture{ 66 | 67 | if (gesture.state == UIGestureRecognizerStateChanged) { 68 | self.transform = CGAffineTransformRotate(self.transform, gesture.rotation); 69 | [gesture setRotation:0]; 70 | } 71 | } 72 | 73 | - (void)panImage:(UIPanGestureRecognizer *)gesture 74 | { 75 | if (gesture.state == UIGestureRecognizerStateChanged) { 76 | CGPoint translation = [gesture translationInView:self.superview]; 77 | [self setCenter:(CGPoint){self.center.x + translation.x, self.center.y + translation.y}]; 78 | [gesture setTranslation:CGPointZero inView:self.superview]; 79 | } 80 | } 81 | 82 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 83 | { 84 | return YES; 85 | } 86 | 87 | #pragma mark - 88 | #pragma mark - Private method 89 | 90 | - (void)setIsSelected:(BOOL)isSelected 91 | { 92 | [super setIsSelected:isSelected]; 93 | if (isSelected) { 94 | self.seperatoeView.layer.borderColor = UIColorFromRGBA(255, 255, 255, 0.5).CGColor; 95 | self.seperatoeView.layer.borderWidth = 2; 96 | }else{ 97 | self.seperatoeView.layer.borderWidth = 0; 98 | } 99 | } 100 | 101 | // 102 | - (void)adjustSizeOfSelect:(CGFloat)scale 103 | { 104 | [super adjustSizeOfSelect:scale]; 105 | 106 | self.seperatoeView.layer.borderColor = UIColorFromRGBA(255, 255, 255, 0.5).CGColor; 107 | self.seperatoeView.layer.borderWidth = 2; 108 | } 109 | 110 | #pragma mark - 111 | #pragma mark - Getter 112 | 113 | - (UIView *)seperatoeView 114 | { 115 | if (!_seperatoeView) { 116 | _seperatoeView = [[UIView alloc] init]; 117 | _seperatoeView.layer.borderColor = UIColorFromRGBA(255, 255, 255, 0.5).CGColor; 118 | _seperatoeView.layer.borderWidth = 2; 119 | } 120 | return _seperatoeView; 121 | } 122 | 123 | - (UILabel *)contentLabel 124 | { 125 | if (!_contentLabel) { 126 | _contentLabel = [[UILabel alloc] init]; 127 | _contentLabel.textAlignment = NSTextAlignmentCenter; 128 | _contentLabel.numberOfLines = 0; 129 | _contentLabel.lineBreakMode = NSLineBreakByWordWrapping; 130 | } 131 | return _contentLabel; 132 | } 133 | 134 | @end 135 | 136 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerHelper/CDPMonitorKeyboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDPMonitorKeyboard.h 3 | // keyboard 4 | // 5 | // Created by 柴东鹏 on 15/4/26. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | 13 | 14 | enum{ 15 | CDPMonitorKeyboardDefaultMode=0,//一般模式(输入视图在主视图,即在self.view上) 16 | CDPMonitorKeyboardTableViewMode,//tableView模式(输入视图在tableView的cell.contentView上且tableView父视图为主视图,即self.view) 17 | CDPMonitorKeyboardScrollViewMode,//scrollView模式(输入视图在scrollView上且scrollView父视图为主视图,即self.view) 18 | }; 19 | typedef NSInteger CDPMonitorKeyboardMode;//模式 20 | 21 | 22 | 23 | 24 | 25 | @protocol CDPMonitorKeyboardDelegate 26 | 27 | /** 28 | * 系统键盘出现时 29 | */ 30 | -(void)didWhenKeyboardWillShow:(NSNotification *)notification; 31 | 32 | /** 33 | * 系统键盘消失时 34 | */ 35 | -(void)didWhenKeyboardWillHide:(NSNotification *)notification; 36 | 37 | @end 38 | 39 | 40 | 41 | @interface CDPMonitorKeyboard : NSObject 42 | 43 | 44 | @property (nonatomic,weak) id delegate; 45 | 46 | /** 47 | * 当isShowKeyboard==YES时,tableView滑动可判断YES时不收起键盘 48 | * 如果项目里写了tableView滑动取消键盘的代码,必须在相关函数里面取消键盘代码前加入此判断 49 | */ 50 | @property (nonatomic,assign,readonly) BOOL isShowKeyboard; 51 | 52 | /** 53 | * 当输入view高于键盘高度时是否仍然自动改变高度(默认为NO,仅限tableViewMode) 54 | */ 55 | @property (nonatomic,assign) BOOL changeWhenHigher; 56 | 57 | /** 58 | * 获取CDPMonitorKeyboard单例 59 | */ 60 | +(CDPMonitorKeyboard *)defaultMonitorKeyboard; 61 | 62 | /** 63 | * 自动监听调用方法(仅需调用一次,若果需要改变参数再调用) 64 | * 一般模式时superView传输入视图所在的主视图即可 65 | * tableView模式时superView传输入视图所在的tableView 66 | * scrollView模式时superView传输入视图所在的scrollView 67 | * valueOfTheHigher为输入视图需要高出键盘的高度 68 | * mode为当前需要的模式(目前共有三种) 69 | * navigationControllerTopHeight为主视图的navigationBar高度+状态栏高度,如没有使用navigationController传0 70 | */ 71 | -(void)sendValueWithSuperView:(UIView *)superView higherThanKeyboard:(NSInteger)valueOfHigher andMode:(CDPMonitorKeyboardMode)mode navigationControllerTopHeight:(NSInteger)topHeight; 72 | 73 | /** 74 | * 清空并重置所有相关数据,防止因为单例造成内存问题(推荐在dealloc中调用) 75 | */ 76 | -(void)clearAll; 77 | 78 | 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerHelper/StoryMakerFontManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // StoryMakerFontManager.h 3 | // InstaGrab 4 | // 5 | // Created by yangl on 15/9/23. 6 | // Copyright (c) 2015年 JellyKit Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StoryMakerFontManager : NSObject 12 | 13 | + (UIFont *)getFontFutura:(CGFloat)fontSize; 14 | 15 | + (UIFont *)getFontFuturaBT:(CGFloat)fontSize; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerHelper/StoryMakerFontManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // FontManager.m 3 | // InstaGrab 4 | // 5 | // Created by yangl on 15/9/23. 6 | // Copyright (c) 2015年 JellyKit Inc. All rights reserved. 7 | // 8 | 9 | #import "StoryMakerFontManager.h" 10 | 11 | @implementation StoryMakerFontManager 12 | 13 | + (UIFont *)getFontFutura:(CGFloat)fontSize { 14 | UIFont* fontLight; 15 | fontLight = [UIFont fontWithName:@"Futura-Medium" size:fontSize]; 16 | 17 | if(fontLight == nil) { 18 | fontLight = [UIFont systemFontOfSize:fontSize]; 19 | } 20 | 21 | return fontLight; 22 | } 23 | 24 | + (UIFont *)getFontFuturaBT:(CGFloat)fontSize { 25 | UIFont* fontLight; 26 | fontLight = [UIFont fontWithName:@"FuturaBT-Light" size:fontSize]; 27 | 28 | if(fontLight == nil) { 29 | fontLight = [UIFont systemFontOfSize:fontSize]; 30 | } 31 | 32 | return fontLight; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerHelper/UIImage+imageWithColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+imageWithColor.h 3 | // PopU 4 | // 5 | // Created by songbo on 14-4-23. 6 | // Copyright (c) 2014年 Pinssible. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (imageWithColor) 12 | 13 | + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size; 14 | + (UIImage *)imageWithColor:(UIColor *)color; 15 | + (UIImage *)imageWithColor:(UIColor *)color withCenter:(UIImage *)centerImage size:(CGSize)size; 16 | + (UIImage *)imageNamed:(NSString *)name withTintColor:(UIColor *)color; 17 | + (UIImage *)convertImageToGreyScale:(UIImage*)image; 18 | + (NSString *)contentTypeForImageData:(NSData *)data; 19 | + (UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize; 20 | + (UIImage *)imageWithImage:(UIImage *)image withTintColor:(UIColor *)color; 21 | + (UIImage *)makeImageWithView:(UIView *)view; 22 | + (UIImage *)Base64StrToUIImage:(NSString *)encodedImageStr; 23 | @end 24 | 25 | 26 | -------------------------------------------------------------------------------- /WHStoryMaker/StoryMakerHelper/UIImage+imageWithColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+imageWithColor.m 3 | // PopU 4 | // 5 | // Created by songbo on 14-4-23. 6 | // Copyright (c) 2014年 Pinssible. All rights reserved. 7 | // 8 | 9 | #import "UIImage+imageWithColor.h" 10 | #import 11 | 12 | @implementation UIImage (imageWithColor) 13 | 14 | + (UIImage *)imageWithColor:(UIColor *)color withCenter:(UIImage *)centerImage size:(CGSize)size 15 | { 16 | UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, size.width, size.height)]; 17 | [background setBackgroundColor:color]; 18 | 19 | UIImageView *imageView = [[UIImageView alloc] initWithImage:centerImage]; 20 | [background addSubview:imageView]; 21 | imageView.center = background.center; 22 | 23 | // Render image 24 | UIGraphicsBeginImageContextWithOptions(background.bounds.size, background.opaque, 0.0); 25 | [background.layer renderInContext:UIGraphicsGetCurrentContext()]; 26 | 27 | UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 28 | 29 | UIGraphicsEndImageContext(); 30 | 31 | return img; 32 | 33 | } 34 | 35 | + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size 36 | { 37 | UIGraphicsBeginImageContext(size); 38 | CGContextRef context = UIGraphicsGetCurrentContext(); 39 | 40 | CGContextSetFillColorWithColor(context, color.CGColor); 41 | CGContextFillRect(context, (CGRect){.size = size}); 42 | 43 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 44 | UIGraphicsEndImageContext(); 45 | 46 | return image; 47 | } 48 | 49 | + (UIImage *)imageWithColor:(UIColor *)color 50 | { 51 | return [UIImage imageWithColor:color size:CGSizeMake(10, 10)]; 52 | } 53 | 54 | + (UIImage *)imageNamed:(NSString *)name withTintColor:(UIColor *)color { 55 | 56 | UIImage *img = [[UIImage imageNamed:name] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 57 | UIGraphicsBeginImageContextWithOptions(img.size, NO, img.scale); 58 | [color set]; 59 | [img drawInRect:CGRectMake(0, 0, img.size.width, img.size.height)]; 60 | img = UIGraphicsGetImageFromCurrentImageContext(); 61 | UIGraphicsEndImageContext(); 62 | return img; 63 | } 64 | 65 | + (UIImage *)convertImageToGreyScale:(UIImage*)image{ 66 | CGRect imageRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height); 67 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); 68 | CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone); 69 | CGContextDrawImage(context, imageRect, [image CGImage]); 70 | CGImageRef imageRef = CGBitmapContextCreateImage(context); 71 | UIImage *newImage = [UIImage imageWithCGImage:imageRef]; 72 | CGColorSpaceRelease(colorSpace); 73 | CGContextRelease(context); 74 | CFRelease(imageRef); 75 | return newImage; 76 | } 77 | 78 | + (NSString *)contentTypeForImageData:(NSData *)data { 79 | if (data==nil) { 80 | return nil; 81 | } 82 | uint8_t c; 83 | [data getBytes:&c length:1]; 84 | 85 | switch (c) { 86 | case 0xFF: 87 | return @"jpeg"; 88 | case 0x89: 89 | return @"png"; 90 | case 0x47: 91 | return @"gif"; 92 | case 0x49: 93 | case 0x4D: 94 | return @"tiff"; 95 | } 96 | return nil; 97 | } 98 | 99 | + (UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize{ 100 | UIGraphicsBeginImageContext(newSize); 101 | [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 102 | UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 103 | UIGraphicsEndImageContext(); 104 | return newImage; 105 | 106 | } 107 | 108 | + (UIImage *)imageWithImage:(UIImage *)image withTintColor:(UIColor *)color { 109 | 110 | UIImage *img = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 111 | UIGraphicsBeginImageContextWithOptions(img.size, NO, img.scale); 112 | [color set]; 113 | [img drawInRect:CGRectMake(0, 0, img.size.width, img.size.height)]; 114 | img = UIGraphicsGetImageFromCurrentImageContext(); 115 | UIGraphicsEndImageContext(); 116 | return img; 117 | } 118 | 119 | + (UIImage *)makeImageWithView:(UIView *)view{ 120 | CGSize s = view.bounds.size; 121 | UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale); 122 | [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 123 | UIImage*image = UIGraphicsGetImageFromCurrentImageContext(); 124 | UIGraphicsEndImageContext(); 125 | return image; 126 | } 127 | 128 | + (UIImage *)Base64StrToUIImage:(NSString *)encodedImageStr{ 129 | if (encodedImageStr.length==0) { 130 | return nil; 131 | } 132 | NSData *decodedImageData = [[NSData alloc] initWithBase64EncodedString:encodedImageStr options:NSDataBase64DecodingIgnoreUnknownCharacters]; 133 | UIImage *decodedImage = [UIImage imageWithData:decodedImageData]; 134 | return decodedImage; 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /WHStoryMaker/WHStoryMakerHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // WHStoryMakerHeader.h 3 | // Demo 4 | // 5 | // Created by whbalzac on 12/08/2017. 6 | // Copyright © 2017 whbalzac. All rights reserved. 7 | // 8 | 9 | #ifndef WHStoryMakerHeader_h 10 | #define WHStoryMakerHeader_h 11 | 12 | #import 13 | #import "Masonry.h" 14 | #import "StoryMakeImageEditorViewController.h" 15 | 16 | #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width 17 | #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height 18 | 19 | #define SCREENAPPLY(x, y) CGSizeMake(SCREEN_WIDTH / 375.0 * (x), SCREEN_HEIGHT / 667.0 * (y)) 20 | #define SCREENAPPLYSPACE(x) SCREEN_WIDTH / 375.0 * (x) 21 | #define SCREENAPPLYHEIGHT(x) SCREEN_HEIGHT / 667.0 * (x) 22 | 23 | #define UIColorFromRGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] 24 | #define UIColorFromRGB(r,g,b) UIColorFromRGBA(r,g,b,1.0) 25 | 26 | static inline BOOL IsEmpty(id thing) { 27 | return thing == nil || [thing isEqual:[NSNull null]] 28 | || ([thing respondsToSelector:@selector(length)] 29 | && [(NSData *)thing length] == 0) 30 | || ([thing respondsToSelector:@selector(count)] 31 | && [(NSArray *)thing count] == 0); 32 | } 33 | 34 | #endif /* WHStoryMakerHeader_h */ 35 | --------------------------------------------------------------------------------