i have implement menu "example.gif" in following library link
i'm using same library blur background. i've used contentinset first 3 rows show bottom.
now, problem when start scrolling entire screen blurred, whereas want blur part of screen uitableviewcells getting scrolled. (ultimately, entire screen blurred first cell reaches top).
how can achieve this. if there workaround without using library, welcome. here code--
class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate, uiscrollviewdelegate{ @iboutlet weak var table: uitableview! var blurview: dkliveblurview! var unsortedcountryarray:[string] = [] override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. let topinset = self.view.frame.height - 120 // array display. let countryarray = nslocale.isocountrycodes() 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 , 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 resources can recreated. } }
this code blurring while scrolling.
to account content inset need change frame provide blurview
eg
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)
edit: old answer
you seem using bounds rather frame dkliveblurview. cause blur view start top left of screen (the origin of view's frame)
try:
self.blurview = dkliveblurview(frame: self.table.frame)
rather
self.blurview = dkliveblurview(frame: self.table.bounds)
Comments
Post a Comment