ios - Add a rectangle on the top edge of my UIView -


i have uiview create in xib file , integrated in storyboard. view tab can drag make appear.

i add little rectangle on top edge when uiview hidden, there little rectangle visible , can pull uiview dragging little rectangle.

to override drawrect method of uiview

override func drawrect(rect: cgrect) {     super.drawrect(rect)      let context = uigraphicsgetcurrentcontext()     cgcontextsetfillcolorwithcolor(context, uicolor.purplecolor().cgcolor)     cgcontextmovetopoint(context, rect.width / 2 - 20, 0)     cgcontextaddlinetopoint(context, rect.width / 2 - 20, -20)     cgcontextaddlinetopoint(context, rect.width / 2 + 20, -20)     cgcontextaddlinetopoint(context, rect.width / 2 + 20, 0)     cgcontextfillpath(context) } 

and when run it, don't see anything, not in view hierarchy...

did wrong?

the rectangle drag has inside view (or separate view) because touches not received views fall outside bounds of superview. way use cashapelayer mask view, , have start 20 points top of view, go top of view @ half width minus 20, etc. give view background color, show through mask is, elsewhere, transparent. in scenario, place view top 20 points on bottom of screen rest being below. rectangle mask sticks top of view color show. here code view class,

class rdpulltabview: uiview {     let upswiper = uiswipegesturerecognizer()     let downswiper = uiswipegesturerecognizer()     let shapelayer = cashapelayer()     let bez = uibezierpath()      required init(coder adecoder: nscoder) {         super.init(coder: adecoder)         self.backgroundcolor = uicolor.purplecolor()         self.layer.mask = shapelayer         upswiper.direction = .up         downswiper.direction = .down         self.addgesturerecognizer(upswiper)         self.addgesturerecognizer(downswiper)     }      override func layoutsubviews() {         super.layoutsubviews()         bez.movetopoint(cgpoint(x: 0, y: 20))         bez.addlinetopoint(cgpoint(x: self.bounds.size.width/2 - 20, y: 20))         bez.addlinetopoint(cgpoint(x: self.bounds.size.width/2 - 20, y: 0))         bez.addlinetopoint(cgpoint(x: self.bounds.size.width/2 + 20, y: 0))         bez.addlinetopoint(cgpoint(x: self.bounds.size.width/2 + 20, y: 20))         bez.addlinetopoint(cgpoint(x: self.bounds.size.width, y: 20))         bez.addlinetopoint(cgpoint(x: self.bounds.size.width, y: self.bounds.size.height))         bez.addlinetopoint(cgpoint(x: 0, y: self.bounds.size.height))         bez.closepath()         shapelayer.path = bez.cgpath     } } 

i made constraint top of view bottom of controller's self.view constant of 20. code in controller this,

class viewcontroller: uiviewcontroller {      @iboutlet weak var pulltabview: rdpulltabview!     @iboutlet weak var bottomcon: nslayoutconstraint!      override func viewdidload() {         super.viewdidload()         pulltabview.upswiper.addtarget(self, action: "handleswipe:")         pulltabview.downswiper.addtarget(self, action: "handleswipe:")     }      func handleswipe(swiper: uiswipegesturerecognizer) {         var point = swiper.locationinview(swiper.view)         if pulltabview.bez.containspoint(point) {             if swiper.direction == uiswipegesturerecognizerdirection.up {                 bottomcon.constant = 200 // 200 height of pulltabview             }else{                 bottomcon.constant = 20;             }             uiview.animatewithduration(0.3){ self.view.layoutifneeded()}         }     } } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -