Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple iOS layer subclass doesn't position right
    primarykey
    data
    text
    <p>What appears when I run this thing is <a href="http://min.us/lyqPi" rel="nofollow">a little off on positioning</a>. It is a simple CALayer subclass with a drawInContext function and positioning it in the view controller.</p> <p>When I create the layer and add it, it is done with this code in the controller code. This runs, so the layer is created. <em>But the position is not correct.</em> It seems to work better in portrait, but I also need ways of detecting the rotation (but that is not my concern immediately).</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; Canvas *c = [Canvas layer]; self.canvas = c; [self.view.layer addSublayer: self.canvas]; //c.frame = self.view.bounds; self.canvas.anchorPoint = CGPointMake(0, 0); self.canvas.position = CGPointMake(0, 0); self.canvas.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height); self.canvas.backgroundColor = [UIColor lightGrayColor].CGColor; [self.canvas setNeedsDisplay]; } </code></pre> <p><strike>The main problem seems to be in the actual drawing, the code follows, but it doesn't actually run even when calling needsDisplay. </strike></p> <pre><code>- (void)drawInContext:(CGContextRef)ctx { [super drawInContext: ctx]; CGContextSaveGState(ctx); UIGraphicsPushContext(ctx); // CGRect b = self.bounds; [self drawOrigin]; UIGraphicsPopContext(); CGContextRestoreGState(ctx); } - (void) drawOrigin { CGPoint centre = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); UIBezierPath *hl = [UIBezierPath bezierPath]; [hl moveToPoint: centre]; [hl addLineToPoint: CGPointMake(centre.x, 0)]; [hl moveToPoint: centre]; [hl addLineToPoint: CGPointMake(centre.x, self.bounds.size.height)]; [hl moveToPoint: centre]; [hl addLineToPoint: CGPointMake(0, centre.y)]; [hl moveToPoint: centre]; [hl addLineToPoint: CGPointMake(self.bounds.size.width, centre.y)]; [hl stroke]; } </code></pre> <p>I don't know where else to look for this code. Any ideas or directions are welcome.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload