-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
2,906 additions
and
625 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ryboardExample/Base.lproj/Main.storyboard → ...ryboardExample/Base.lproj/Main.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
StoryboardExample/StoryboardExample/PageController/FooldView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// FooldView.swift | ||
// PageController | ||
// | ||
// Created by Mark on 15/10/20. | ||
// Copyright © 2015年 Wecan Studio. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class FooldView: ProgressView { | ||
|
||
// MARK: - Vars | ||
var hollow = false | ||
private var margin: CGFloat = 0.0 | ||
private var radius: CGFloat = 0.0 | ||
private var height: CGFloat = 0.0 | ||
|
||
// MARK: - Private funcs | ||
override func willMoveToSuperview(newSuperview: UIView?) { | ||
height = frame.size.height | ||
margin = height * 0.15 | ||
radius = (height - margin * 2.0) / 2.0 | ||
} | ||
|
||
override func drawRect(rect: CGRect) { | ||
// Drawing code | ||
let currentIndex = Int(progress) | ||
let rate = progress - CGFloat(currentIndex) | ||
let nextIndex = (currentIndex + 1) >= itemFrames.count ? currentIndex : currentIndex + 1 | ||
let currentFrame = itemFrames[currentIndex] | ||
let currentWidth = currentFrame.size.width | ||
let currentX = currentFrame.origin.x | ||
let nextWidth = itemFrames[nextIndex].size.width | ||
let nextX = self.itemFrames[nextIndex].origin.x | ||
let startX = currentX + (nextX - currentX) * rate | ||
let endX = startX + currentWidth + (nextWidth - currentWidth) * rate | ||
let ctx = UIGraphicsGetCurrentContext() | ||
CGContextTranslateCTM(ctx, 0.0, height) | ||
CGContextScaleCTM(ctx, 1.0, -1.0) | ||
CGContextAddArc(ctx, startX + radius, height / 2.0, radius, CGFloat(M_PI_2), CGFloat(M_PI_2) * 3, 0) | ||
CGContextAddLineToPoint(ctx, endX - radius, margin) | ||
CGContextAddArc(ctx, endX - radius, height / 2.0, radius, CGFloat(-M_PI_2), CGFloat(M_PI_2), 0) | ||
CGContextClosePath(ctx) | ||
if hollow == true { | ||
CGContextSetStrokeColorWithColor(ctx, color) | ||
CGContextStrokePath(ctx) | ||
return | ||
} | ||
CGContextClosePath(ctx) | ||
CGContextSetFillColorWithColor(ctx, color) | ||
CGContextFillPath(ctx) | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
StoryboardExample/StoryboardExample/PageController/MenuItem.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// MenuItem.swift | ||
// PageController | ||
// | ||
// Created by Mark on 15/10/20. | ||
// Copyright © 2015年 Wecan Studio. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol MenuItemDelegate: NSObjectProtocol { | ||
func didSelectedMenuItem(menuItem: MenuItem) | ||
} | ||
|
||
class MenuItem: UILabel { | ||
|
||
// MARK: - Public vars | ||
var normalSize: CGFloat = 15.0 | ||
var selectedSize: CGFloat = 18.0 | ||
weak var delegate: MenuItemDelegate? | ||
|
||
var selected = false { | ||
didSet { rate = (selected == false) ? 0.0 : 1.0 } | ||
} | ||
|
||
var rate: CGFloat = 0.0 { | ||
didSet { | ||
let red = normalComponents.red + (selectedComponets.red - normalComponents.red) * rate | ||
let green = normalComponents.green + (selectedComponets.green - normalComponents.green) * rate | ||
let blue = normalComponents.blue + (selectedComponets.blue - normalComponents.blue) * rate | ||
let alpha = normalComponents.alpha + (selectedComponets.alpha - normalComponents.alpha) * rate | ||
let minScale = normalSize / selectedSize | ||
let trueScale = minScale + (1 - minScale) * rate | ||
textColor = UIColor(red: red, green: green, blue: blue, alpha: alpha) | ||
transform = CGAffineTransformMakeScale(trueScale, trueScale) | ||
} | ||
} | ||
|
||
var normalColor: UIColor? { | ||
didSet { | ||
normalColor?.getRed(&normalComponents.red, green: &normalComponents.green, blue: &normalComponents.blue, alpha: &normalComponents.alpha) | ||
} | ||
} | ||
|
||
var selectedColor: UIColor? { | ||
didSet { | ||
selectedColor?.getRed(&selectedComponets.red, green: &selectedComponets.green, blue: &selectedComponets.blue, alpha: &selectedComponets.alpha) | ||
} | ||
} | ||
|
||
// MARK: - Private vars | ||
private var normalComponents: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) = (0.0, 0.0, 0.0, 0.0) | ||
private var selectedComponets: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) = (0.0, 0.0, 0.0, 0.0) | ||
|
||
// MARK: - Public funcs | ||
func selectWithAnimation(select: Bool) -> Void { | ||
if selected == select { return } | ||
UIView.animateWithDuration(0.3) { () -> Void in | ||
if self.selected == true { | ||
self.rate = 0.0 | ||
} else { | ||
self.rate = 1.0 | ||
} | ||
self.selected = select | ||
} | ||
} | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setup() | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
setup() | ||
} | ||
|
||
// MARK: - Private funcs | ||
private func setup() { | ||
textAlignment = NSTextAlignment.Center | ||
userInteractionEnabled = true | ||
backgroundColor = UIColor.clearColor() | ||
} | ||
|
||
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { | ||
delegate?.didSelectedMenuItem(self) | ||
} | ||
} |
Oops, something went wrong.