Github에서 찾은 Parallax 테이블 뷰의 하위 클래스 인 tableView가 있습니다. 모든 테이블보기를 정상적으로 설정했습니다 (관련이없는 부분부터 일부를 삭제했습니다).viewDidLayoutSubviews와 함께 UITableView 스크롤을 감지하면 과도한 콜백이 발생합니다.
class EventDetailTableViewController: ParallaxTableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Set the image:
self.imageView.image = eventImage
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
}
// MARK: - UITableViewDelegate
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 4
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// SET UP CELL
}
@IBAction func backButtonPressed(sender: AnyObject) {
print("backButtonPressed")
self.navigationController?.navigationBar.translucent = false
self.navigationController?.navigationBar.barTintColor = UIColor(red: 227/255, green: 38/255, blue: 54/255, alpha: 1.0)
self.navigationController?.popViewControllerAnimated(true)
}
} // END OF VIEWCONTROLLER CLASS
여기서 주목해야 할 중요한 사항은 navigationBar
을 투명하게 만들었습니다. backButtonPressed
이 호출되면 navigationBar.Color
을 이전 View Controller (빨간색)의 색으로 되돌리고 싶습니다. 그래서 나는 그것을 코딩했습니다. backButtonPressed()
여기 제가 가지고있는 시차 코드입니다. 마지막 기능은 moveImage()
입니다. 나는 아래까지 충분히 navigationBar
제목 "이벤트 설명"당신은 내 노트에서 볼 수 있듯이
class ParallaxTableViewController: UITableViewController {
// Create the UIView
//var bottomFloatingView = UIView()
// Create the UIImageView
let imageView = UIImageView()
// Set the factor for the parallaxEffect. This is overwritable.
var parallaxFactor:CGFloat = 2
// Set the default height for the image on the top.
var imageHeight:CGFloat = 320 {
didSet {
moveImage()
}
}
// Initialize the scrollOffset varaible.
var scrollOffset:CGFloat = 0 {
didSet {
moveImage()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Set the contentInset to make room for the image.
self.tableView.contentInset = UIEdgeInsets(top: imageHeight, left: 0, bottom: 0, right: 0)
// Change the contentMode for the ImageView.
imageView.contentMode = UIViewContentMode.ScaleAspectFill
// Add the imageView to the TableView and send it to the back.
view.addSubview(imageView)
view.sendSubviewToBack(imageView)
}
override func viewDidLayoutSubviews() {
// Update the image position after layout changes.
moveImage()
}
// Define method for image location changes.
func moveImage() {
let imageOffset = (scrollOffset >= 0) ? scrollOffset/parallaxFactor : 0
let imageHeight = (scrollOffset >= 0) ? self.imageHeight : self.imageHeight - scrollOffset
imageView.frame = CGRect(x: 0, y: -imageHeight + imageOffset, width: view.bounds.width, height: imageHeight)
if imageOffset > 150 {
print("imageOffSet")
self.navigationItem.title = "Event Description"
self.navigationController?.navigationBar.translucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController?.navigationBar.shadowImage = nil
} else {
print("else")
self.navigationItem.title = ""
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
// This is being called after the back button is being pressed. Which means this else function overrides my backButtonPressed() therefore making my navigation bar in the new VC not the correct color.
}
}
}
에 표시되는 설명에있는 tableview의 스크롤이 다른 기능이 후 다시 호출 될 때의 간단한 효과를 backButtonPressed()
이 호출됩니다. 그러므로 새로운 VC에서 원하는 빨강을주지는 않지만 반투명으로 남겨 둡니다. 어떻게하면 backButtonPressed가 호출 될 때이 다른 함수가 호출되는 것을 멈출 수 있습니까?
다른 이미지를 호출하는 경우 'imageOffset <150'이 좋습니다. 아마도 수학을 확인하고 무엇이 깨지는 지 찾아야 할 것입니다. –