ios - subViews only displayed when bezierPath is created using origin =0,0 and size = size of subView -
i trying improve uikit skills working on simple block breaking game. i.e view have 9 sub-views on top (each corresponding block) , have paddle , ball ball breaking blocks.
i have blockview class sub-class of uiview following init , drawrect: methods. noticing first block sub-view displayed when drawrect
contains first statement (i.e bezierpath created framerect property) blockviews displayed when drawrect
called when bezierpath created cgrect origin = 0,0 , appropriate size.
i have confirmed self.framerect has origin = columnblocksize, rowblockheight , appropriate size.
could please explain why bezierpath should created wth origin = 0,0 , not @ right offset 0,0?
is because of how drawrect called? i.e co-ordinate system has been translated when drawrect called on sub-view corresponding blockview
-(instancetype) initwithframe:(cgrect)frame andcolor:(int) color { self = [super initwithframe:frame]; if (self) { self.color = color; self.framerect = frame; } return self; } - (void)drawrect:(cgrect)rect { //using statement create bezierpaths shows first block //uibezierpath *block = [uibezierpath bezierpathwithrect:self.framerect]; //using sequence, results in displaying blocks cgrect blockrect = cgrectmake(0, 0, self.bounds.size.width, self.bounds.size.height); uibezierpath *block = [uibezierpath bezierpathwithrect:blockrect]; switch (self.color) { case red: [[uicolor redcolor] setfill]; break; case blue: [[uicolor bluecolor] setfill]; break; case green: [[uicolor greencolor] setfill]; break; default: break; } [block fill]; }
Comments
Post a Comment