Skip to content

Commit

Permalink
Web内容页主体功能制作完成 但仍有bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zpz1237 committed Oct 8, 2015
1 parent 4d498e2 commit f394b11
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,4 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,32 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "zhihuDaily 2.0/WebViewController.swift"
timestampString = "465995449.60477"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
landmarkName = "WebViewController"
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
2 changes: 1 addition & 1 deletion zhihuDaily 2.0/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<!--Web View Controller-->
<scene sceneID="DVn-sv-E7e">
<objects>
<viewController id="6rh-4x-mHf" customClass="WebViewController" customModule="知乎日报" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="webViewController" id="6rh-4x-mHf" customClass="WebViewController" customModule="知乎日报" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="1MM-8R-3Xh"/>
<viewControllerLayoutGuide type="bottom" id="rJd-xL-ofz"/>
Expand Down
58 changes: 56 additions & 2 deletions zhihuDaily 2.0/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class WebViewController: UIViewController, UIScrollViewDelegate, ParallaxHeaderV
var sourceLabel: UILabel!
var blurView: GradientView!
var refreshImageView: UIImageView!
var dragging = false
var triggered = false

//滑到对应位置时调整StatusBar
var statusBarFlag = true {
var statusBarFlag = false {
didSet {
UIView.animateWithDuration(0.2) { () -> Void in
print("statusdiaoyong")
self.setNeedsStatusBarAppearanceUpdate()
}
}
Expand All @@ -49,6 +52,10 @@ class WebViewController: UIViewController, UIScrollViewDelegate, ParallaxHeaderV
override func viewDidLoad() {
super.viewDidLoad()

statusBarFlag = true

self.view.clipsToBounds = true

//设置展示的imageView
imageView = UIImageView(frame: CGRectMake(0, 0, self.view.frame.width, 223))
imageView.contentMode = .ScaleAspectFill
Expand Down Expand Up @@ -143,8 +150,14 @@ class WebViewController: UIViewController, UIScrollViewDelegate, ParallaxHeaderV
blurView.insertTwiceTransparentGradient()

//如果下拉超过65pixels则改变图片方向
if incrementY < -65 {
if incrementY <= -65 {
arrowState = true
//如果此时是第一次检测到松手则加载上一篇
guard dragging || triggered else {
loadNewArticle(true)
triggered = true
return
}
} else {
arrowState = false
}
Expand All @@ -171,14 +184,55 @@ class WebViewController: UIViewController, UIScrollViewDelegate, ParallaxHeaderV
webHeaderView.layoutWebHeaderViewForScrollViewOffset(scrollView.contentOffset)
}

//记录下拉状态
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
dragging = false
}

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
dragging = true
}

//设置滑动极限 修改该值需要一并更改layoutWebHeaderViewForScrollViewOffset中的对应值
func lockDirection() {
self.webView.scrollView.contentOffset.y = -85
}

//加载新文章
func loadNewArticle(previous: Bool) {
//生成动画初始位置
//let offScreenUp = CGAffineTransformMakeTranslation(0, -self.view.frame.height - 85)
let offScreenUp = CGAffineTransformMakeTranslation(0, -self.view.frame.height)
let offScreenDown = CGAffineTransformMakeTranslation(0, self.view.frame.height)

//生成新View并传入新数据
let toWebViewController = self.storyboard!.instantiateViewControllerWithIdentifier("webViewController") as! WebViewController
let toView = toWebViewController.view
toView.frame = self.view.frame

//将新View放置到屏幕之外并添加到ScrollView上
toView.transform = offScreenUp
//webView.scrollView.addSubview(toView)
self.view.addSubview(toView)
webView.removeFromSuperview()
statusBarBackground.removeFromSuperview()
self.addChildViewController(toWebViewController)

//动画开始
UIView.animateWithDuration(0.2, animations: { () -> Void in
//当前View下滑出屏幕,新View滑入屏幕
// self.view.transform = offScreenDown
// self.view.alpha = 0.5
toView.transform = CGAffineTransformIdentity
}, completion: { (success) -> Void in
print("动画执行完成")
})
}

//依据statusBarFlag返回StatusBar颜色
override func preferredStatusBarStyle() -> UIStatusBarStyle {
if statusBarFlag {
//bug:当切换页面后statusBarFlag即便被设置为false,执行该函数时会却变成true.. 待解决
return .LightContent
}
return .Default
Expand Down

0 comments on commit f394b11

Please sign in to comment.