fix setActive

This commit is contained in:
nixzhu
2015-08-04 17:39:59 +08:00
parent b275e4bc82
commit 50c72d04c7
3 changed files with 42 additions and 24 deletions
@@ -60,13 +60,13 @@ class SkillHomeViewController: CustomNavigationBarViewController {
willSet {
switch newValue {
case .Master:
headerView.learningButton.setInActive()
headerView.masterButton.setActive()
headerView.learningButton.setInActive(animated: !isFirstAppear)
headerView.masterButton.setActive(animated: !isFirstAppear)
skillHomeScrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
case .Learning:
headerView.masterButton.setInActive()
headerView.learningButton.setActive()
headerView.masterButton.setInActive(animated: !isFirstAppear)
headerView.learningButton.setActive(animated: !isFirstAppear)
skillHomeScrollView.setContentOffset(CGPoint(x: masterTableView.frame.size.width, y: 0), animated: true)
}
@@ -203,6 +203,12 @@ class SkillHomeViewController: CustomNavigationBarViewController {
}
customTitleView()
if isFirstAppear {
state = preferedState ?? .Master
isFirstAppear = false
}
}
override func viewDidLayoutSubviews() {
@@ -223,16 +229,6 @@ class SkillHomeViewController: CustomNavigationBarViewController {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if isFirstAppear {
isFirstAppear = false
state = preferedState ?? .Master
}
}
// MARK: UI
func customTitleView() {
@@ -74,8 +74,6 @@ class SkillHomeHeaderView: UIView {
override func layoutSubviews() {
super.layoutSubviews()
masterButton.setActive()
headerImageView.frame = self.bounds
masterButton.frame = CGRectMake(0, self.frame.height - YepConfig.skillHomeHeaderButtonHeight, self.frame.size.width/2.0, YepConfig.skillHomeHeaderButtonHeight)
@@ -15,24 +15,48 @@ class SkillHomeSectionButton: UIButton {
let highLight = CALayer()
func setActive() {
UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: nil, animations: {
func setActive(#animated: Bool) {
let setting: () -> Void = {
self.highLight.frame = CGRectMake(0, self.frame.size.height - skillHeomSectionButtonLineHeight, self.frame.size.width, skillHeomSectionButtonLineHeight)
self.highLight.backgroundColor = UIColor.yepTintColor().CGColor
}, completion: nil)
println("highLight.frame: \(self.highLight.frame)")
}
if animated {
UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: nil, animations: {
setting()
}, completion: nil)
} else {
setting()
}
}
func setInActive() {
func setInActive(#animated: Bool) {
UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: nil, animations: {
let setting: () -> Void = {
self.highLight.frame = CGRectMake(0, self.frame.size.height - skillHeomSectionButtonLineHeight, self.frame.size.width, skillHeomSectionButtonLineHeight)
self.highLight.backgroundColor = UIColor.yepDisabledColor().CGColor
}, completion: nil)
}
if animated {
UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: nil, animations: {
setting()
}, completion: nil)
} else {
setting()
}
}
func updateHightLightBounce() {
highLight.frame = CGRectMake(0, self.frame.size.height - skillHeomSectionButtonLineHeight, self.frame.size.width, 0)
highLight.frame = CGRectMake(0, self.frame.size.height - skillHeomSectionButtonLineHeight, self.frame.size.width, skillHeomSectionButtonLineHeight)
}
}