gpt4 book ai didi

ios - 如何仅模糊 uitableview 滚动的部分

转载 作者:行者123 更新时间:2023-11-28 06:37:23 26 4
gpt4 key购买 nike

我必须在以下库中实现一个菜单,就像“example.gif”一样 link

我正在使用同一个库来模糊背景。我使用了 contentInset,以便从底部开始显示前三行。

现在,我的问题是当我开始滚动时整个屏幕都变得模糊,而我想模糊 uitableviewcells 正在滚动的屏幕部分。 (最终,当第一个单元格到达顶部时,整个屏幕将变得模糊)。

我怎样才能做到这一点。如果有任何不使用该库的解决方法,也欢迎提供。这是代码——

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate{

@IBOutlet weak var table: UITableView!

var blurView: DKLiveBlurView!

var unsortedCountryArray:[String] = []

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

let topInset = self.view.frame.height - 120

// Array to display.
let countryArray = NSLocale.ISOCountryCodes()

for countryCode in countryArray {
let displayNameString = NSLocale.currentLocale().displayNameForKey(NSLocaleCountryCode, value: countryCode)
if displayNameString != nil {
unsortedCountryArray.append(displayNameString!)
}
}

// =============setting background==============
// self.bkgView = UIImageView(frame: self.view.bounds)
// self.bkgView.image = UIImage(named: "bg1")
// self.bkgView.contentMode = .ScaleAspectFill
// self.view.addSubview(self.bkgView)

// self.blurredBkgView = UIImageView(frame: self.view.bounds)
// self.blurredBkgView.image = UIImage(named: "bg1")
// self.blurredBkgView.contentMode = .ScaleAspectFill
// self.view.addSubview(blurredBkgView)

// self.blurredBkgView.alpha = 0.0

//
// blurEffect = UIBlurEffect(style: .Light)
// visualEffectView = UIVisualEffectView(effect: blurEffect)
// visualEffectView.frame = self.blurredBkgView.bounds
// self.visualEffectView.alpha = 0.0
// self.view.addSubview(self.visualEffectView)

self.table.backgroundColor = UIColor.clearColor()
self.table.separatorColor = UIColor.clearColor()
self.table.contentInset = UIEdgeInsetsMake(topInset, 0, 0, 0)
self.table.rowHeight = 40

print("view bounds: \(self.view.bounds)\n and table bounds: \(self.table.bounds)")
self.blurView = DKLiveBlurView(frame: self.table.bounds)
self.blurView.originalImage = UIImage(named: "bg1")
self.blurView.scrollView = table
self.blurView.setBlurLevel(6.0)
self.blurView.isGlassEffectOn = true
self.table.backgroundView = self.blurView


}

func scrollViewDidScroll(scrollView: UIScrollView) {
// let height = CGFloat(scrollView.bounds.size.height)
// let position = max(scrollView.contentOffset.y, 0.0)
// let percent = min(position / height, 1.0)
// self.blurredBkgView.alpha = percent;

// print("scrollview bounds: \(scrollView.bounds)")
}

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// cell.backgroundView = self.blurView

}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return unsortedCountryArray.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
cell.textLabel?.text = unsortedCountryArray[indexPath.row]
cell.textLabel?.textColor = UIColor.blueColor()
cell.backgroundColor = UIColor.clearColor()
cell.selectionStyle = .None
return cell
}



override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

这么多代码在滚动时会变得模糊。

最佳答案

为了说明您的内容,您需要更改提供给 blurView 的框架

例如

let contentInset = CGFloat(/*Your content inset*/)
let blurFrame = CGRect(x: 0, y: contentInset, width: tableView.frame.width, height: tableView.frame.height - contentInset)
self.blurView = DKLiveBlurView(frame: blurFrame)

编辑:旧答案

您似乎在为 DKLiveBlurView 使用边界而不是框架。这将导致您模糊 View 从屏幕的左上角开始( View 框架的原点)

尝试:

self.blurView = DKLiveBlurView(frame: self.table.frame)

而不是

self.blurView = DKLiveBlurView(frame: self.table.bounds)

关于ios - 如何仅模糊 uitableview 滚动的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38835593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com