Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView and UIViewController practice for inheritance
    primarykey
    data
    text
    <p>I was just wondering if this approach looks like a good practice for apps with a lot of custom views, for nested PNG graphics and animations that may change based on user interaction. I created a BaseView class that extends UIView</p> <pre><code>@interface BaseView : UIView { @protected BaseViewController *controller; } @property (retain) BaseViewController *controller; @end </code></pre> <p>and a corresponding controller class which is the primary location which I am putting code to manipulate the view</p> <pre><code>@interface BaseViewController : UIViewController { @protected CGRect drawArea; } - (void) drawArea:(CGRect) _drawArea; - (CGRect) drawArea; - (void) linkSubviewController: (BaseViewController *) _subviewController; @end </code></pre> <p>where "drawArea" is the CGRect used to pass to the view as a frame.</p> <p>"linkSubviewController" allows you to nest a controller and view as follows :</p> <pre><code>- (void) linkSubviewController: (BaseViewController *) _subviewController { [self.view addSubview:[_subviewController view]]; } </code></pre> <p>In addition I layered another custom pair called "ImageView" and "ImageViewController" which extend BaseView but also store a UIImage and an x,y,w,h</p> <p>In the "drawRect" drawing methods on views I can check to see if any vars in the self.controller vars have been changed, or assign images, for example :</p> <pre><code>UIImage *image = [(ImageViewController *)self.controller image]; CGContextDrawImage( ... ) etc </code></pre> <p>I write most of the loadView methods something like this</p> <pre><code>- (void)loadView { ImageView *v = [[ImageView new] initWithFrame:drawArea]; v.controller = self; self.view = v; } </code></pre> <p>The base "initWithFrame" routine contains</p> <pre><code> self.backgroundColor = [UIColor clearColor]; self.opaque = NO; </code></pre> <p>So I can load a variety of images with transparent backgrounds without having to assign that each time.</p> <p>I've been able to use this code throughout my app and it seems to make it easy to write a top level class which assembles the layout of custom items. For animations I've been putting them in the controllers and manipulating self.view.layer.</p> <p>Basically I am looking for feedback, I am new with Objective-C and the IPhone SDK</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.
 

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