2017-11-09 5 views
0

tableView의 배경으로 사용자 그라디언트가있는 레이어를 삽입하려고합니다. 그러나 테이블 앞에 표시됩니다.CAGradientLayer를 인덱스 0 (tableView 뒤)에 삽입 할 수 없습니다.

이전에는 작동했지만 XCode를 업데이트하면 작동하지 않습니다.

let statusBarHeight = UIApplication.shared.statusBarFrame.height 
    let gradient = self.getMenuGradientLayer() 

    gradient.frame = CGRect(x: 0, y: -statusBarHeight, width: self.view.frame.width, height: statusBarHeight + self.view.bounds.height) 

    // Tried multiple options. Not at the same time, of course. 
    self.view.layer.insertSublayer(gradient, at: 0) // Worked previously 
    self.tableView.layer.insertSublayer(gradient, at: 0) 
    self.tableView.backgroundView?.layer.insertSublayer(gradient, at: 0) 

이러한 옵션 중 일부는 그래디언트를 전혀 표시하지 않지만 일부는 테이블 전면에 표시합니다.

클래스 자체는 UITableViewController입니다.

나는이 코드를 viewDidLoad, viewWillAppear, viewWillLayoutSubviews에 구현하려고 시도했다.

같은 것 ...

답변

0

tableView 속성을 사용하여 작업을 실행하는 다른 방법을 찾았습니다. 이전 솔루션은 작업을 중지 이유

let statusBarHeight = UIApplication.shared.statusBarFrame.height 
    let frame = CGRect(x: 0, y: -statusBarHeight, width: self.view.frame.width, height: statusBarHeight + self.view.bounds.height) 

    let gradient = self.getMenuGradientLayer() 

    gradient.frame = frame 

    let backgroundView = UIView(frame: frame) 

    backgroundView.layer.insertSublayer(gradient, at: 0) 

    self.tableView.backgroundView = backgroundView 

그러나, 여전히 ...

이해하지 않는다
관련 문제