This is the demos to show 30 demos finishes in 30 days (or more)
Switch branches/tags
Nothing to show
Clone or download
Latest commit 8ec36a1 Jul 7, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
01.CustomFont update 01 to swift 4 and change snapkit to version 3.2 Apr 10, 2018
02.Watch'sDemo fix bug Apr 14, 2018
03.Find My Position update to swift 4.1 (to project 12) Apr 11, 2018
04.Limit Input Text Field update to swift 4.1 (to project 12) Apr 11, 2018
05.Pull To Refresh update to swift 4.1 (to project 12) Apr 11, 2018
06.Video Player update to swift 4.1 (to project 12) Apr 11, 2018
07.Simple Photo Browser update to swift 4.1 (to project 12) Apr 11, 2018
08.Color Gradient update to swift 4.1 (to project 12) Apr 11, 2018
09.Swipeable Cell update to swift 4.1 (to project 12) Apr 11, 2018
10.Stretchy Header update to swift 4.1 (to project 12) Apr 11, 2018
11.Gradient in TableView update to swift 4.1 (to project 12) Apr 11, 2018
12.Emoji Slot Machine update to swift 4.1 (to project 12) Apr 11, 2018
13.AnimationInTableViewCell add resources Apr 12, 2018
14.VideoSplash update to Swfit 4.1 Apr 14, 2018
15.Tumblr Menu delete useless folders Jul 7, 2018
16.LoginAnimation update to swfit 4.1 Apr 13, 2018
17.3D Touch Quick Action update to swfit 4.1 Apr 13, 2018
18.Spotlight Search update to swfit 4.1 Apr 13, 2018
19.TodayWidget update to swfit 4.1 Apr 13, 2018
20.WatchApp Guess update to swfit 4.1 Apr 13, 2018
21.CoreDataApp update to swfit 4.1 Apr 13, 2018
22.Basic Animations update to swfit 4.1 Apr 13, 2018
23.Side Navigation update to swfit 4.1 Apr 13, 2018
24.Vertical Menu Transition update to swfit 4.1 Apr 13, 2018
25.CustomTransition update to swfit 4.1 Apr 13, 2018
26.TwitterLikeSplash update to swfit 4.1 Apr 13, 2018
27.Carousel Effect update to swfit 4.1 Apr 13, 2018
28.SnapChatLikeApp update ato swfit 4.1 Apr 14, 2018
29.Beauty Contest update ato swfit 4.1 Apr 14, 2018
30.Google Now update ato swfit 4.1 Apr 14, 2018
README.md Update README.md Apr 14, 2018
bannerForSwift.png Add files via upload Jun 5, 2017

README.md

All the codes have been updated to Swift 4.1.

30-swift-projects-in-30-days

中文版:抓住iOS的未来 - 30天学习编写30个Swift小程序

For any problem, please send me the e-mail: egeg3000@gmail.com.

Project 30 - Google Now App

GoogleNow.gif

What I learned:

  • How to do Transition Animation for Present/Dismiss
  • How to do combine animation based on BubbleTransition
  • Draw round button, the codes are:
triggerButton.layer.cornerRadius = triggerButton.frame.width / 2
triggerButton.layer.masksToBounds = true

Project 29 - Beauty Contest

BeautyContest.gif

What I learned

  • This project is based on Yalantis的Koloda, Koloda is a very useful UIImage Selector.
  • Two ways to use lazy load in Swift:
lazy var firstWay = "first"

And

lazy var secondWay: String = {return "Second"}()

Warning: For the second way, you must define the TYPE FIRST, so the complier could check in the beginning.

Project 28 - SnapChat Like App

Snap Chat Like App.gif

What I learned

  • Usage of UIScrollView, e.g., how to forbidden bounces property, isPagingEnabled property, and contentOffset property
  • How to use addChildViewController
  • How to use AVCaptureSession

Project 27: Carousel Effect (跑马灯效果)

Carousel Effect.gif

What I learned

  • Usage of UICollectionView, for example, to deal with padding within cells, you could adjust with minimumLineSpacingForSection
  • To customize a layout, you need to realize such func:
        prepare()
        shouldInvalidateLayout(forBoundsChange newBounds: CGRect)
        targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) 
        layoutAttributesForElements(in rect: CGRect)
  • Usage of Visual Effect View

Project 26 - Twitter-like Splash

TwitterLikeSplash.gif

What I learned

  • Usage of CAAnimation
  • reference of Keypath in CAAnimation
  • add Key Animation Frame by using CAKeyFrameAnimation

Project 25 Custom Transition

CustomTransition.gif

What I learned

  • We can customize animation of navigationcontroller, that is to say, to implement the func in UINavigationControllerDelegate
  • If we only need to focus on fromVC & toVC, we only need to implement such methods:
navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?

Project 24 - Vertical Menu Transition

Vertical Menu Transition.gif

What I learned

  • Customize naviation transition for Present/Dismiss
  • Generally speaking, for target-action, we will set target to "self". But if we set target to "delegate", then the action should be set #selector(CustomTransitionDelegate.functionName)
  • In the transition Animation complete block, please insert following func:
    transitionContext.completeTransition(true)
    fromViewController?.endAppearanceTransition()
    toViewController?.endAppearanceTransition()

Project 23 - Side Navigation App

SideNavigation.gif

What I learned

  • Mix Swift with Objective-C
    • New a head file, e.g., Bridge.h
    • Click Project file, then Build Setting, then Objective-C Bridge Header, set the file path in Bridge.h
    • Then import all the header files in Bridge.h
  • Learned how to use SWRevealViewController

Project 22 - Basic Animations

Basic Animations.gif

What I learned

  • For animation related to position, we can both implement by modify the origin, and by setting the transform property of UIView
  • For animation related to Opacity, we can modify the alpha directly
  • For animation related to Scale, set the transform property of UIView, e.g.:
heartView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
  • For animation related to Color, modify the backgroundColor property
  • For animation related to Rotation, set the Scale Object to transform, e.g.:
heartView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)

Project 21 CoreData App

CoreDataAppDemo.gif

What I learned

  • In order to autogenerate some codes for you, please check UseCoreData while creating new project.
  • Don't have to use Editor to generate Subclass
  • Reference

Project 20 - Apple Watch OS App - Guess Game

WatchApp_Guess.gif

What I learned

  • Need to select Watch OS while creating the project.
  • Have to use Storyboard to do the layout for apple watch, and the related file is Interface.storyboard
  • Use WCSession to do the interaction between Watch and Main App
  • Usecase refer too:WatchKit Introduction: Building a Simple Guess Game

Project 19 - TodayWidget

TodayWidget.gif

What I learned

  • Create Today Widget: "File > New > Target",then select the iOS section's "Application Extension's Today Extension"
  • In order to share data between widget and app, please open the "App group" function. "target -> capability -> App Group -> Open it"
  • Add the group and name it, then redo this steps in Extension's target, and select the group you created just now.
  • Can use UserDefault as the shared storage between Main App and Widget, but we can't use StandardUserDefaults here, only to use suitName, and the name must follow the named group, e.g.:
let userDefault = UserDefaults(suiteName: "group.nimoAndHisFriend.watchDemo")

Project 18 - Spotlight Search

SpotlightSearch.gif

What I learned

  • How to use Spotlight Search:
    • import CoreSpotlight
    • Add the object as CSSearchableItem: Create a CSSearchableItemAttributeSet, then fill it's properties, such as title, contentDescription, and thumbData
    • CSSearchableItemAttribuitSet's thumbData can be catched either by UIImageJPEGRepresentation or by UIImagePNGRepresentation(Depend on the type of photo)
    • Create CSSearchableItem Obj, then add to SearchIndex by indexSearchableItems:
let tmpItems = [searchItem]
CSSearchableIndex.default().indexSearchableItems(tmpItems) { (error) in
}
  • If you face problems in debug, please reset the simulator, or just debug with Device.

Project 17 - 3D Touch Quick Action

3DTouchQuickAction.gif

  • Please make sure the application can support 3D Press function: self.window?.traitCollection.forceTouchCapability == .available
  • There are two kinds of operation with 3D Press: By long press icon in Spring Board(destop in iOS), and by long press some certain element and have a Peek View in Application.
  • For the first type, create the item with UIApplicationShortcutItem, then set the application's shortcutItems property. Please remember, you can't use custom icon.
  • For the second type, please add related event in the ViewController you want to:
    • implement UIViewControllerPreviewingDelegate
    • register 3D Touch support : self.registerForPreviewing(with: self, sourceView: self.view)
    • implement following methods:
    func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? 
    func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) 

Project 16 - LoginAnimation

LoginAnimation.gif

What I learned

  • Bounce animation need to use ```usingSpringWithDamping````, and please pay attention to:
    • usingSpringWithDamping:the less the more exaggerate
    • initialSpringVelocity: the initial speed of animation
    • options: you can choose the animation method, such as EaseIn, EaseOut, EaseInOut...
  • ReferenceDoc1,Doc2
  • This kind of animation is so amazing, I like it :P

Project 15 - Tumblr Menu

Tumblr Menu.gif

What I learned

  • animation + BlurEffect
  • These lines of icon's appearing has a sequence, please control it by setting different delay value
  • For custom button, I refered to :Custom Button

Project 14 - Video Splash

VideoSplash.gif

What I learned

  • Create an AVPlayerViewController, then set it as the background of View
  • Then autoplay with AVPlayerViewController
  • Refered to a lib called VideoSplashViewController

Project 13: Animation In TableViewCell

AnimationInTableViewCell.gif

What I learned

  • Do the animation in method: viewWillAppear. Then get all the cells by visibleCells of tableView, then do enumerate it and do animation
  • Do animation by using usingSpringWithDamping, set 0.8 to usingSpringWithDamping, 0 to initalSpringVelocity.

Project 12 - Emoji Slot Machine

Emoji Slot Machine.gif

What I learned

  • Use UIPicker to do this game
  • In order to avoid show the edge of the UIPickerView, the first value and the last value of UIPickerView is forbidden. Int(arc4random())%(emojiArray.count - 2) + 1
  • Add double click action to make sure it will trigger the 'bingo'
  • I love this game. :)

Project 11 - Gradient in TableView

GradientInTableView.gif

What I learned

  • Use CAGradientLayer on UITableViewCell
  • I suggest to use CAGradientLayer as the backgroundView of cell
  • hide the useless style of UITableViewCell:
      table.separatorStyle = .none
      cell.selectionStyle = .none

Project 10 - Stretchy Header

Stretchy Header.gif

What I learned

  • get the offset of ScrollView by implementing scrollViewDidScroll of UIScrollView
  • then set Max and Min of the scale for picture
  • set the transform of UIImageView to finish it:
bannerImgView.transform = CGAffineTransform(scaleX: scaleFactor, y: scaleFactor)

Project 9 - Swipeable Cell

Swipeable Cell.gif

What I learned

  • use editActionsForRowAt for UItableView, and set the functions as a array to the return value:Array<UITableViewRowAction>
  • for each action please init UITableViewRowAction, and set the logic in block.
  • this demo only for general usage of swipeable cell, if you want to custom the swiped button, you must customize the Cell and implement functions by UIPanGesture

Project 8 - Color Gradient

ColorGradient.gif

What I learned

  • Use CAGradientLayer for the Gradient effect
  • Color set's concept will help to make the array of color. Please pay attention hat the property is CGColor
  • Changing color by scrolling is implemented by PanGestureRecognizer, and the effect and operation refered to : Solar

Project 7 - Simple Photo Browser

SimplePhotoBrowser.gif

What I learned

  • Set imageView on ScrollView to do Image Zoom
  • Set maxZoomScale / minZoomScale
  • implement viewForZooming method

Project 6 - Video Player

Video Player.gif

What I learned

  • How to use AVPlayer, AVPlayerViewController and AVPlayerLayer
  • How to run app in background by do configuration in plist
  • Show info in Lock Screen(remoteControlReceived)
  • Grammer: do...catch...
  • Reference

Project 5 - Pull To Refresh

PullToRefresh.gif

What I learned

  • Usage of UIRefreshControll: message: attributedTitle, action: UIControlEvents.valueChanged

Project 4 - Limited Input Text Field

Limit Input Text Field.gif

What I learned

  • limit input by capturing texting method: textViewDidChange
  • By observing NSNotification.Name.UIKeyboardWillChangeFrame, we can get the pop and dismiss of system keyboard.

Project 3 - Find My Position

Find My Position.gif

What I learned

  • configuration of location: in plist, please add: NSLocationAlwaysUsageDescription

  • can use CLLocationManger to do locate

  • if you face Domain=GEOErrorDomain Code=-8 "(null)", please change CLGeocoder var to global var

Project 2: Watch Demo

Watch's Demo.gif

What I learned

  • Update cocoaPods to 1.2.0
  • Learn how to use SnapKit (Quite similar with Monsary)
  • Learn how to use Timer in Swift
  • What I learned: guard,refer to guard

Project 1: Change Custom Font

Custom Font.gif

What I learned

  • How to change property of font
  • we could search font name in Storyboard, or following codes:
       func printAllSupportedFontNames() {
        let familyNames = UIFont.familyNames
        for familyName in familyNames {
            print("++++++ \(familyName)")
            let fontNames = UIFont.fontNames(forFamilyName: familyName)
            for fontName in fontNames {
                print("----- \(fontName)")
            }}}