Optimizing AI for immediate response in Smart CCTV
December 2014 University iOS Meetup Talk
1. View controller lifecycle
@ University iOS Meetup
December 2, 2014
1024 x 768
9 slides
Overpass =
bebas neue =
image
2. When will then be now?
Ben Gohlke December 2, 2014
university ios
View Controller
Lifecycle
3. View Lifecycle
• UIViewController loads its view programmatically or via storyboard/
nib.
• Several methods are called on UIViewController instance to provide
an opportunity for customization.
• Layout
• Content
December 2, 2014
university ios
4. Programmatic Initialization
• Override loadView method in your view controller.
• Do NOT call super on loadView
• Create a root view object and set its frame (usu. same as window or
container)
• Create any subviews and add them to their parent using addSubview:
• If using autolayout, add constraints to subviews
• If not, use viewWillLayoutSubviews and
viewDidLayoutSubviews
December 2, 2014
university ios
5. Load from a nib or storyboard
• Lay out subviews in nib or storyboard
• Xcode packages these objects in an archive which is unpacked at
runtime. Your app will gain control of fully instantiated and
configured objects.
• Not necessarily laid out though.
December 2, 2014
university ios
@interface MyViewController()
@property (nonatomic) IBOutlet UIButton *myButton;
@property (nonatomic) IBOutlet UIButton *myTextField;
- (IBAction)myAction:(id)sender;
@end
6. Tweaking the layout
• viewWillLayoutSubviews, called right before subviews are laid out.
Opportunity to override and make changes to view before layout.
• viewDidLayoutSubviews, called right after subviews are laid out (not
guaranteed that all subviews have adjusted their layouts).
December 2, 2014
university ios
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
self.view.superview.bounds = CGRectMake(0, 0, 540, 400);
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
CGFloat imageViewWidth = CGRectGetWidth(self.anImageView.bounds);
CGFloat multiplier = imageViewWidth / self.anImageView.image.size.width;
CGFloat adjustedHeight = ceilf(self.anImageView.image.size.height * multiplier);
[self.anImageViewHeightConstraint setConstraint:adjustedHeight];
}
}