Skip to content

Commit

Permalink
第24天 - MosiacLayout,配合Pods的使用
Browse files Browse the repository at this point in the history
  • Loading branch information
qianyb committed Dec 27, 2018
1 parent b966d34 commit 7593514
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ playground.xcworkspace
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
Pods/

# Carthage
#
Expand Down
57 changes: 53 additions & 4 deletions Project 24 - MosaicLayout/MosaicLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0BD13530C42B0829626D32F9 /* Pods-MosaicLayout.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MosaicLayout.release.xcconfig"; path = "Pods/Target Support Files/Pods-MosaicLayout/Pods-MosaicLayout.release.xcconfig"; sourceTree = "<group>"; };
638048473C6D879DC272832B /* Pods-MosaicLayout.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MosaicLayout.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MosaicLayout/Pods-MosaicLayout.debug.xcconfig"; sourceTree = "<group>"; };
9FC96C8C1C5E74330064708F /* MosaicLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MosaicLayout.app; sourceTree = BUILT_PRODUCTS_DIR; };
9FC96C8F1C5E74330064708F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9FC96C911C5E74330064708F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +88,15 @@
name = Frameworks;
sourceTree = "<group>";
};
4266BBE54D8B5621B9809FF3 /* Pods */ = {
isa = PBXGroup;
children = (
638048473C6D879DC272832B /* Pods-MosaicLayout.debug.xcconfig */,
0BD13530C42B0829626D32F9 /* Pods-MosaicLayout.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
9FC96C831C5E74330064708F = {
isa = PBXGroup;
children = (
Expand All @@ -94,6 +105,7 @@
9FC96CAE1C5E74330064708F /* MosaicLayoutUITests */,
9FC96C8D1C5E74330064708F /* Products */,
3E0BBA01FD6A2B5F79B8AD2A /* Frameworks */,
4266BBE54D8B5621B9809FF3 /* Pods */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -146,12 +158,13 @@
isa = PBXNativeTarget;
buildConfigurationList = 9FC96CB41C5E74330064708F /* Build configuration list for PBXNativeTarget "MosaicLayout" */;
buildPhases = (
C7C5E161573236E2F218C5E0 /* [CP] Check Pods Manifest.lock */,
2EC5A36C5B556AE3B343AA43 /* Check Pods Manifest.lock */,
9FC96C881C5E74330064708F /* Sources */,
9FC96C891C5E74330064708F /* Frameworks */,
9FC96C8A1C5E74330064708F /* Resources */,
EA7F7A0A973C5D096835035C /* Embed Pods Frameworks */,
D5977757A1A56F9C581E7971 /* Copy Pods Resources */,
076C05C4F64FEDEAF395EFD6 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -210,6 +223,7 @@
TargetAttributes = {
9FC96C8B1C5E74330064708F = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = F3YT8BWBYJ;
};
9FC96C9F1C5E74330064708F = {
CreatedOnToolsVersion = 7.2;
Expand Down Expand Up @@ -269,6 +283,32 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
076C05C4F64FEDEAF395EFD6 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-MosaicLayout/Pods-MosaicLayout-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
"${BUILT_PRODUCTS_DIR}/FLKAutoLayout/FLKAutoLayout.framework",
"${BUILT_PRODUCTS_DIR}/FMMosaicLayout/FMMosaicLayout.framework",
"${BUILT_PRODUCTS_DIR}/ORStackView/ORStackView.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FLKAutoLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FMMosaicLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ORStackView.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MosaicLayout/Pods-MosaicLayout-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
2EC5A36C5B556AE3B343AA43 /* Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -284,19 +324,22 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
D5977757A1A56F9C581E7971 /* Copy Pods Resources */ = {
C7C5E161573236E2F218C5E0 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "Copy Pods Resources";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-MosaicLayout-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MosaicLayout/Pods-MosaicLayout-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
EA7F7A0A973C5D096835035C /* Embed Pods Frameworks */ = {
Expand Down Expand Up @@ -460,28 +503,34 @@
};
9FC96CB51C5E74330064708F /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 638048473C6D879DC272832B /* Pods-MosaicLayout.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = F3YT8BWBYJ;
INFOPLIST_FILE = MosaicLayout/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.appkitchen.MosaicLayout;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "MosaicLayout/MosaicLayout-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
9FC96CB61C5E74330064708F /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 0BD13530C42B0829626D32F9 /* Pods-MosaicLayout.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = F3YT8BWBYJ;
INFOPLIST_FILE = MosaicLayout/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.appkitchen.MosaicLayout;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "MosaicLayout/MosaicLayout-Bridging-Header.h";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
26 changes: 1 addition & 25 deletions Project 24 - MosaicLayout/MosaicLayout/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
// 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.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// 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.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

25 changes: 12 additions & 13 deletions Project 24 - MosaicLayout/MosaicLayout/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15E33e" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="NZh-Gw-YF3">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="NZh-Gw-YF3">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down Expand Up @@ -31,16 +34,13 @@
<rect key="frame" x="0.0" y="0.0" width="80" height="80"/>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<color key="backgroundColor" red="0.98319345712661743" green="0.37615275382995605" blue="0.52669250965118408" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.96658921241760254" green="0.27144032716751099" blue="0.45319151878356934" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="AH2-kH-cgO" secondAttribute="trailing" constant="-8" id="0t5-VW-z4H"/>
<constraint firstItem="AH2-kH-cgO" firstAttribute="top" secondItem="36c-Tg-Xu4" secondAttribute="topMargin" constant="-8" id="3U4-sn-lpH"/>
<constraint firstAttribute="bottomMargin" secondItem="AH2-kH-cgO" secondAttribute="bottom" constant="-8" id="7q2-Eb-FIT"/>
<constraint firstItem="AH2-kH-cgO" firstAttribute="centerX" secondItem="36c-Tg-Xu4" secondAttribute="centerX" id="UqS-Bb-TG7"/>
<constraint firstItem="AH2-kH-cgO" firstAttribute="leading" secondItem="36c-Tg-Xu4" secondAttribute="leadingMargin" constant="-8" id="YlD-DB-GhI"/>
<constraint firstItem="AH2-kH-cgO" firstAttribute="centerY" secondItem="36c-Tg-Xu4" secondAttribute="centerY" id="l0a-e0-9Fx"/>
<constraint firstItem="AH2-kH-cgO" firstAttribute="leading" secondItem="36c-Tg-Xu4" secondAttribute="leading" id="Otc-he-qro"/>
<constraint firstAttribute="trailing" secondItem="AH2-kH-cgO" secondAttribute="trailing" id="bEf-QT-MeX"/>
<constraint firstAttribute="bottom" secondItem="AH2-kH-cgO" secondAttribute="bottom" id="l51-zN-VLf"/>
<constraint firstItem="AH2-kH-cgO" firstAttribute="top" secondItem="36c-Tg-Xu4" secondAttribute="top" id="r8c-Qa-yjS"/>
</constraints>
</collectionViewCell>
</cells>
Expand All @@ -49,7 +49,6 @@
<outlet property="delegate" destination="NZh-Gw-YF3" id="xq6-0F-u2R"/>
</connections>
</collectionView>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina47"/>
</collectionViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="et9-Ng-cqN" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
2 changes: 2 additions & 0 deletions Project 24 - MosaicLayout/MosaicLayout/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
</plist>
75 changes: 30 additions & 45 deletions Project 24 - MosaicLayout/MosaicLayout/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,87 +9,72 @@
import UIKit
import FMMosaicLayout

class ViewController: UICollectionViewController, FMMosaicLayoutDelegate {
class ViewController: UICollectionViewController {

var imageArray = [String]()

override func viewDidLoad() {
super.viewDidLoad()

imageArray = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"]

let mosaicLayout : FMMosaicLayout = FMMosaicLayout()
let mosaicLayout = FMMosaicLayout()
self.collectionView?.collectionViewLayout = mosaicLayout

if #available(iOS 11.0, *) {
self.collectionView?.contentInsetAdjustmentBehavior = .never
}
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.lightContent
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}


func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, numberOfColumnsInSection section: Int) -> Int {
return 1
}

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 10
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath)

let randomBlue = CGFloat(drand48())
let randomRed = CGFloat(drand48())
let randomGreen = CGFloat(drand48())

cell.backgroundColor = UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
cell.alpha = 0

let imageView = cell.viewWithTag(2) as! UIImageView
let imageView = cell.contentView.viewWithTag(2) as! UIImageView
imageView.image = UIImage(named: imageArray[indexPath.row])


let cellDelay = UInt64((arc4random() % 600 ) / 1000 )

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(cellDelay * NSEC_PER_SEC )), dispatch_get_main_queue(), ({ () -> Void in

UIView.animateWithDuration(0.8, animations: ({

let cellDelayTime = DispatchTime(uptimeNanoseconds: cellDelay * NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: cellDelayTime) {
UIView.animate(withDuration: 0.8, animations: {
cell.alpha = 1.0

}))

}))
})
}

return cell

}

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
}

extension ViewController : FMMosaicLayoutDelegate {

func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, insetForSectionAtIndex section: Int) -> UIEdgeInsets {

return UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)
func collectionView(_ collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, numberOfColumnsInSection section: Int) -> Int {
return 3
}

func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, interitemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 1.0
func collectionView(_ collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, mosaicCellSizeForItemAt indexPath: IndexPath!) -> FMMosaicCellSize {
return indexPath.item % 7 == 0 ? .big : .small
}

func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, mosaicCellSizeForItemAtIndexPath indexPath: NSIndexPath! ) -> FMMosaicCellSize {
return indexPath.item % 7 == 0 ? FMMosaicCellSize.Big : FMMosaicCellSize.Small
func collectionView(_ collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, interitemSpacingForSectionAt section: Int) -> CGFloat {
return 1.0
}



func collectionView(_ collectionView: UICollectionView!, layout collectionViewLayout: FMMosaicLayout!, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)
}

}

Loading

0 comments on commit 7593514

Please sign in to comment.