Updated formatting

This commit is contained in:
Joe Blau 2015-02-02 06:39:18 -08:00
parent 3be228a61b
commit 2fb05f1940
9 changed files with 247 additions and 290 deletions

65
.clang-format Normal file
View File

@ -0,0 +1,65 @@
Language: Cpp
AccessModifierOffset: -4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: false
PointerAlignment: Left
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
# Only available on clang-format 3.6
# AlwaysBreakAfterDefinitionReturnType: true
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakBeforeBraces: Attach
BinPackParameters: true
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
Cpp11BracedListStyle: false
Standard: Cpp03
TabWidth: 8
UseTab: Never
NamespaceIndentation: Inner
IndentWidth: 4
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
SpacesBeforeTrailingComments: 1
SpaceBeforeParens: ControlStatements
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
DisableFormat: false
...

View File

@ -1,34 +1,33 @@
//
// COSTouchVisualizerWindow.h
//
// TouchVisualizer
//
// Created by Joe Blau on 3/22/14.
// Copyright (c) 2014 conopsys. All rights reserved.
//
//
#import <UIKit/UIKit.h>
@protocol COSTouchVisualizerWindowDelegate;
@interface COSTouchVisualizerWindow : UIWindow
@property (nonatomic, assign, readonly, getter=isActive) BOOL active;
@property (nonatomic, readonly, getter=isActive) BOOL active;
@property (nonatomic, weak) id<COSTouchVisualizerWindowDelegate> touchVisualizerWindowDelegate;
@property (nonatomic, strong) UIImage *touchImage;
@property (nonatomic, assign) CGFloat touchAlpha;
@property (nonatomic, assign) NSTimeInterval fadeDuration;
@property (nonatomic, strong) UIColor *strokeColor;
@property (nonatomic, strong) UIColor *fillColor;
// Touch effects
@property (nonatomic) UIImage* touchImage;
@property (nonatomic) CGFloat touchAlpha;
@property (nonatomic) NSTimeInterval fadeDuration;
@property (nonatomic) UIColor* strokeColor;
@property (nonatomic) UIColor* fillColor;
// Ripple Effects
@property (nonatomic, strong) UIImage *rippleImage;
@property (nonatomic, assign) CGFloat rippleAlpha;
@property (nonatomic, assign) NSTimeInterval rippleFadeDuration;
@property (nonatomic, strong) UIColor *rippleStrokeColor;
@property (nonatomic, strong) UIColor *rippleFillColor;
@property (nonatomic) UIImage* rippleImage;
@property (nonatomic) CGFloat rippleAlpha;
@property (nonatomic) NSTimeInterval rippleFadeDuration;
@property (nonatomic) UIColor* rippleStrokeColor;
@property (nonatomic) UIColor* rippleFillColor;
@property (nonatomic) BOOL stationaryMorphEnabled; // default: YES
@property (nonatomic) BOOL stationaryMorphEnabled; // default: YES
@end
@ -36,7 +35,7 @@
@optional
- (BOOL)touchVisualizerWindowShouldShowFingertip:(COSTouchVisualizerWindow *)window;
- (BOOL)touchVisualizerWindowShouldAlwaysShowFingertip:(COSTouchVisualizerWindow *)window;
- (BOOL)touchVisualizerWindowShouldShowFingertip:(COSTouchVisualizerWindow*)window;
- (BOOL)touchVisualizerWindowShouldAlwaysShowFingertip:(COSTouchVisualizerWindow*)window;
@end

View File

@ -1,70 +1,69 @@
//
// COSTouchVisualizerWindow.m
//
// TouchVisualizer
//
// Created by Joe Blau on 3/22/14.
// Copyright (c) 2014 conopsys. All rights reserved.
//
#import "COSTouchVisualizerWindow.h"
#pragma mark - Conopsys Touch Spot View
@interface COSTouchSpotView : UIImageView
@property (nonatomic, assign) NSTimeInterval timestamp;
@property (nonatomic, assign) BOOL shouldAutomaticallyRemoveAfterTimeout;
@property (nonatomic, assign, getter=isFadingOut) BOOL fadingOut;
@property (nonatomic) NSTimeInterval timestamp;
@property (nonatomic) BOOL shouldAutomaticallyRemoveAfterTimeout;
@property (nonatomic, getter=isFadingOut) BOOL fadingOut;
@end
@implementation COSTouchSpotView
@end
#pragma mark - Conopsys Touch Overlay Window View Controller
@interface COSTouchOverlayWindowViewController : UIViewController
@end
#pragma mark -
@implementation COSTouchOverlayWindowViewController
- (UIStatusBarStyle)preferredStatusBarStyle {
return [UIApplication sharedApplication].keyWindow.rootViewController.preferredStatusBarStyle;
}
@end
#pragma mark - Conopsys Touch Visualizer Window
@interface COSTouchVisualizerWindow ()
@property (nonatomic, strong) UIWindow *overlayWindow;
@property (nonatomic, strong) UIViewController *overlayWindowViewController;
@property (nonatomic, assign) BOOL fingerTipRemovalScheduled;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic) UIWindow* overlayWindow;
@property (nonatomic) UIViewController* overlayWindowViewController;
@property (nonatomic) BOOL fingerTipRemovalScheduled;
@property (nonatomic) NSTimer* timer;
- (void)COSTouchVisualizerWindow_commonInit;
- (void)scheduleFingerTipRemoval;
- (void)cancelScheduledFingerTipRemoval;
- (void)removeInactiveFingerTips;
- (void)removeFingerTipWithHash:(NSUInteger)hash animated:(BOOL)animated;
- (BOOL)shouldAutomaticallyRemoveFingerTipForTouch:(UITouch *)touch;
- (BOOL)shouldAutomaticallyRemoveFingerTipForTouch:(UITouch*)touch;
@end
#pragma mark -
@implementation COSTouchVisualizerWindow
@synthesize touchImage = _touchImage;
@synthesize touchAlpha = _touchAlpha;
@synthesize fadeDuration = _fadeDuration;
@synthesize rippleImage = _rippleImage;
@synthesize rippleAlpha = _rippleAlpha;
@synthesize rippleFadeDuration = _rippleFadeDuration;
@synthesize overlayWindow = _overlayWindow;
@synthesize overlayWindowViewController = _overlayWindowViewController;
@synthesize active = _active;
@synthesize fingerTipRemovalScheduled = _fingerTipRemovalScheduled;
- (id)initWithCoder:(NSCoder *)decoder {
- (id)initWithCoder:(NSCoder*)decoder {
// This covers NIB-loaded windows.
self = [super initWithCoder:decoder];
if (self != nil)
if (self = [super initWithCoder:decoder])
[self COSTouchVisualizerWindow_commonInit];
return self;
}
- (id)initWithFrame:(CGRect)rect {
// This covers programmatically-created windows.
self = [super initWithFrame:rect];
if (self != nil)
if (self = [super initWithFrame:rect])
[self COSTouchVisualizerWindow_commonInit];
return self;
}
@ -72,28 +71,24 @@
- (void)COSTouchVisualizerWindow_commonInit {
self.strokeColor = [UIColor blackColor];
self.fillColor = [UIColor whiteColor];
self.rippleStrokeColor = [UIColor whiteColor];
self.rippleFillColor = [UIColor blueColor];
self.touchAlpha = 0.5;
self.fadeDuration = 0.3;
self.rippleAlpha = 0.2;
self.rippleFadeDuration = 0.2;
self.stationaryMorphEnabled = YES;
}
#pragma mark -
- (UIImage *)touchImage {
- (UIImage*)touchImage {
if (!_touchImage) {
UIBezierPath *clipPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 50.0, 50.0)];
UIBezierPath* clipPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 50.0, 50.0)];
UIGraphicsBeginImageContextWithOptions(clipPath.bounds.size, NO, 0);
UIBezierPath *drawPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(25.0, 25.0)
UIBezierPath* drawPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(25.0, 25.0)
radius:22.0
startAngle:0
endAngle:2 * M_PI
@ -115,13 +110,13 @@
return _touchImage;
}
- (UIImage *)rippleImage {
- (UIImage*)rippleImage {
if (!_rippleImage) {
UIBezierPath *clipPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 50.0, 50.0)];
UIBezierPath* clipPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 50.0, 50.0)];
UIGraphicsBeginImageContextWithOptions(clipPath.bounds.size, NO, 0);
UIBezierPath *drawPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(25.0, 25.0)
UIBezierPath* drawPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(25.0, 25.0)
radius:22.0
startAngle:0
endAngle:2 * M_PI
@ -143,28 +138,26 @@
return _rippleImage;
}
#pragma mark -
#pragma mark Active
- (BOOL)anyScreenIsMirrored {
if (![UIScreen instancesRespondToSelector:@selector(mirroredScreen)])
return NO;
for (UIScreen *screen in [UIScreen screens]) {
if ([screen mirroredScreen] != nil)
for (UIScreen* screen in [UIScreen screens]) {
if ([screen mirroredScreen] != nil) {
return YES;
}
}
return NO;
}
- (BOOL)isActive {
// should show fingertip or not
if (![self.touchVisualizerWindowDelegate
respondsToSelector:@selector(touchVisualizerWindowShouldShowFingertip:)] ||
if (![self.touchVisualizerWindowDelegate respondsToSelector:@selector(touchVisualizerWindowShouldShowFingertip:)] ||
[self.touchVisualizerWindowDelegate touchVisualizerWindowShouldShowFingertip:self]) {
// should always show or only when any screen is mirrored.
return (([self.touchVisualizerWindowDelegate
respondsToSelector:@selector(touchVisualizerWindowShouldAlwaysShowFingertip:)] &&
return (([self.touchVisualizerWindowDelegate respondsToSelector:@selector(touchVisualizerWindowShouldAlwaysShowFingertip:)] &&
[self.touchVisualizerWindowDelegate touchVisualizerWindowShouldAlwaysShowFingertip:self]) ||
[self anyScreenIsMirrored]);
} else {
@ -172,18 +165,17 @@
}
}
#pragma mark -
#pragma mark UIWindow overrides
- (void)sendEvent:(UIEvent *)event {
- (void)sendEvent:(UIEvent*)event {
if (self.active) {
NSSet *allTouches = [event allTouches];
for (UITouch *touch in [allTouches allObjects]) {
NSSet* allTouches = [event allTouches];
for (UITouch* touch in [allTouches allObjects]) {
switch (touch.phase) {
case UITouchPhaseBegan:
case UITouchPhaseMoved: {
// Generate ripples
COSTouchSpotView *rippleView = [[COSTouchSpotView alloc] initWithImage:self.rippleImage];
COSTouchSpotView* rippleView = [[COSTouchSpotView alloc] initWithImage:self.rippleImage];
[self.overlayWindow addSubview:rippleView];
rippleView.alpha = self.rippleAlpha;
@ -191,17 +183,22 @@
[UIView animateWithDuration:self.rippleFadeDuration
delay:0.0
options:UIViewAnimationOptionCurveEaseIn // See other options
options:UIViewAnimationOptionCurveEaseIn // See other
// options
animations:^{
[rippleView setAlpha:0.0];
[rippleView setFrame:CGRectInset(rippleView.frame, 25, 25)];
[rippleView setAlpha:0.0];
[rippleView setFrame:CGRectInset(rippleView.frame, 25, 25)];
}
completion:^(BOOL finished) { [rippleView removeFromSuperview]; }];
completion:^(BOOL finished) {
[rippleView removeFromSuperview];
}];
}
case UITouchPhaseStationary: {
COSTouchSpotView *touchView = (COSTouchSpotView *)[self.overlayWindow viewWithTag:touch.hash];
COSTouchSpotView* touchView = (COSTouchSpotView*)
[self.overlayWindow viewWithTag:touch.hash];
if (touch.phase != UITouchPhaseStationary && touchView != nil && [touchView isFadingOut]) {
if (touch.phase != UITouchPhaseStationary && touchView != nil &&
[touchView isFadingOut]) {
[self.timer invalidate];
[touchView removeFromSuperview];
touchView = nil;
@ -219,18 +216,15 @@
repeats:YES];
}
}
if (![touchView isFadingOut]) {
touchView.alpha = self.touchAlpha;
touchView.center = [touch locationInView:self.overlayWindow];
touchView.tag = touch.hash;
touchView.timestamp = touch.timestamp;
touchView.shouldAutomaticallyRemoveAfterTimeout =
[self shouldAutomaticallyRemoveFingerTipForTouch:touch];
touchView.shouldAutomaticallyRemoveAfterTimeout = [self shouldAutomaticallyRemoveFingerTipForTouch:touch];
}
break;
}
case UITouchPhaseEnded:
case UITouchPhaseCancelled: {
[self removeFingerTipWithHash:touch.hash animated:YES];
@ -242,20 +236,22 @@
[super sendEvent:event];
[self scheduleFingerTipRemoval]; // We may not see all UITouchPhaseEnded/UITouchPhaseCancelled events.
[self scheduleFingerTipRemoval]; // We may not see all
// UITouchPhaseEnded/UITouchPhaseCancelled
// events.
}
#pragma mark -
#pragma mark Private
- (UIWindow *)overlayWindow {
- (UIWindow*)overlayWindow {
if (!_overlayWindow) {
_overlayWindow = [[UIWindow alloc] initWithFrame:self.frame];
_overlayWindow.userInteractionEnabled = NO;
_overlayWindow.windowLevel = UIWindowLevelStatusBar;
_overlayWindow.backgroundColor = [UIColor clearColor];
_overlayWindow.hidden = NO;
_overlayWindowViewController = [[COSTouchOverlayWindowViewController alloc] init];
[_overlayWindow setRootViewController:_overlayWindowViewController];
[_overlayWindowViewController setView:_overlayWindow];
@ -268,12 +264,16 @@
if (self.fingerTipRemovalScheduled)
return;
self.fingerTipRemovalScheduled = YES;
[self performSelector:@selector(removeInactiveFingerTips) withObject:nil afterDelay:0.1];
[self performSelector:@selector(removeInactiveFingerTips)
withObject:nil
afterDelay:0.1];
}
- (void)cancelScheduledFingerTipRemoval {
self.fingerTipRemovalScheduled = YES;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(removeInactiveFingerTips) object:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(removeInactiveFingerTips)
object:nil];
}
- (void)removeInactiveFingerTips {
@ -282,25 +282,21 @@
NSTimeInterval now = [[NSProcessInfo processInfo] systemUptime];
const CGFloat REMOVAL_DELAY = 0.2;
for (COSTouchSpotView *touchView in [self.overlayWindow subviews]) {
if (![touchView isKindOfClass:[COSTouchSpotView class]])
continue;
for (COSTouchSpotView* touchView in [self.overlayWindow subviews]) {
if (![touchView isKindOfClass:[COSTouchSpotView class]]) continue;
if (touchView.shouldAutomaticallyRemoveAfterTimeout && now > touchView.timestamp + REMOVAL_DELAY)
[self removeFingerTipWithHash:touchView.tag animated:YES];
}
if ([[self.overlayWindow subviews] count])
[self scheduleFingerTipRemoval];
if ([[self.overlayWindow subviews] count]) [self scheduleFingerTipRemoval];
}
- (void)removeFingerTipWithHash:(NSUInteger)hash animated:(BOOL)animated {
COSTouchSpotView *touchView = (COSTouchSpotView *)[self.overlayWindow viewWithTag:hash];
if (touchView == nil)
return;
COSTouchSpotView* touchView = (COSTouchSpotView*)[self.overlayWindow viewWithTag:hash];
if (touchView == nil) return;
if ([touchView isFadingOut])
return;
if ([touchView isFadingOut]) return;
BOOL animationsWereEnabled = [UIView areAnimationsEnabled];
@ -310,9 +306,9 @@
[UIView setAnimationDuration:self.fadeDuration];
}
touchView.frame =
CGRectMake(touchView.center.x - touchView.frame.size.width, touchView.center.y - touchView.frame.size.height,
touchView.frame.size.width * 2, touchView.frame.size.height * 2);
touchView.frame = CGRectMake(touchView.center.x - touchView.frame.size.width,
touchView.center.y - touchView.frame.size.height,
touchView.frame.size.width * 2, touchView.frame.size.height * 2);
touchView.alpha = 0.0;
@ -322,10 +318,12 @@
}
touchView.fadingOut = YES;
[touchView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:self.fadeDuration];
[touchView performSelector:@selector(removeFromSuperview)
withObject:nil
afterDelay:self.fadeDuration];
}
- (BOOL)shouldAutomaticallyRemoveFingerTipForTouch:(UITouch *)touch;
- (BOOL)shouldAutomaticallyRemoveFingerTipForTouch:(UITouch*)touch;
{
// We don't reliably get UITouchPhaseEnded or UITouchPhaseCancelled
// events via -sendEvent: for certain touch events. Known cases
@ -339,85 +337,69 @@
// don't use UITouchPhaseStationary touches for those. *sigh*). So we
// end up with this more complicated setup.
UIView *view = [touch view];
UIView* view = [touch view];
view = [view hitTest:[touch locationInView:view] withEvent:nil];
while (view != nil) {
if ([view isKindOfClass:[UITableViewCell class]]) {
for (UIGestureRecognizer *recognizer in [touch gestureRecognizers]) {
if ([recognizer isKindOfClass:[UISwipeGestureRecognizer class]])
return YES;
for (UIGestureRecognizer* recognizer in [touch gestureRecognizers]) {
if ([recognizer isKindOfClass:[UISwipeGestureRecognizer class]]) return YES;
}
}
if ([view isKindOfClass:[UITableView class]]) {
if ([[touch gestureRecognizers] count] == 0)
return YES;
if ([[touch gestureRecognizers] count] == 0) return YES;
}
view = view.superview;
}
return NO;
}
- (void)performMorph:(NSTimer *)theTimer {
UIView *view = (UIView *)[theTimer userInfo];
- (void)performMorph:(NSTimer*)theTimer {
UIView* view = (UIView*)[theTimer userInfo];
NSTimeInterval duration = .4;
NSTimeInterval delay = 0;
// Start
view.alpha = _touchAlpha;
view.alpha = self.touchAlpha;
view.transform = CGAffineTransformMakeScale(1, 1);
[UIView animateWithDuration:duration / 4
delay:delay
options:0
animations:^{
// End
view.transform = CGAffineTransformMakeScale(1, 1.2);
// End
view.transform = CGAffineTransformMakeScale(1, 1.2);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:duration / 4
delay:0
options:0
animations:^{
// End
view.transform = CGAffineTransformMakeScale(1.2, 0.9);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:duration / 4
delay:0
options:0
animations:^{
[UIView animateWithDuration:duration / 4
delay:0
options:0
animations:^{
// End
view.transform = CGAffineTransformMakeScale(1.2, 0.9);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:duration / 4
delay:0
options:0
animations:^{
// End
view.transform = CGAffineTransformMakeScale(0.9, 0.9);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:duration / 4
delay:0
options:0
animations:^{
// End
view.transform = CGAffineTransformMakeScale(0.9, 0.9);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:duration / 4
delay:0
options:0
animations:^{
// End
view.transform = CGAffineTransformMakeScale(1, 1);
}
completion:^(BOOL finished){
view.transform = CGAffineTransformMakeScale(1, 1);
}
completion:^(BOOL finished){
}];
}];
}];
}];
}];
}];
}];
}
@end
#pragma mark -
@implementation COSTouchSpotView
@end
@implementation COSTouchOverlayWindowViewController
- (UIStatusBarStyle)preferredStatusBarStyle {
return [UIApplication sharedApplication].keyWindow.rootViewController.preferredStatusBarStyle;
}
@end

View File

@ -6,10 +6,8 @@
// Copyright (c) 2014 conopsys. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface COSAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic) UIWindow* window;
@end

View File

@ -10,64 +10,33 @@
#import <COSTouchVisualizerWindow.h>
@interface COSAppDelegate () <COSTouchVisualizerWindowDelegate>
@end
@implementation COSAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (COSTouchVisualizerWindow *)window
{
static COSTouchVisualizerWindow *customWindow = nil;
if (!customWindow) {
customWindow = [[COSTouchVisualizerWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[customWindow setFillColor:[UIColor yellowColor]];
[customWindow setStrokeColor:[UIColor purpleColor]];
[customWindow setTouchAlpha:0.4];
[customWindow setRippleFillColor:[UIColor yellowColor]];
[customWindow setRippleStrokeColor:[UIColor purpleColor]];
[customWindow setRippleAlpha:0.1];
[customWindow setTouchVisualizerWindowDelegate:self];
}
return customWindow;
- (COSTouchVisualizerWindow*)window {
static COSTouchVisualizerWindow* customWindow = nil;
if (!customWindow) {
customWindow = [[COSTouchVisualizerWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[customWindow setFillColor:[UIColor yellowColor]];
[customWindow setStrokeColor:[UIColor purpleColor]];
[customWindow setTouchAlpha:0.4];
[customWindow setRippleFillColor:[UIColor yellowColor]];
[customWindow setRippleStrokeColor:[UIColor purpleColor]];
[customWindow setRippleAlpha:0.1];
[customWindow setTouchVisualizerWindowDelegate:self];
}
return customWindow;
}
- (BOOL)touchVisualizerWindowShouldAlwaysShowFingertip:(COSTouchVisualizerWindow *)window
{
- (BOOL)touchVisualizerWindowShouldAlwaysShowFingertip:(COSTouchVisualizerWindow*)window {
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end

View File

@ -6,11 +6,9 @@
// Copyright (c) 2014 conopsys. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface COSDetailViewController : UIViewController
@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel* detailDescriptionLabel;
@end

View File

@ -16,36 +16,23 @@
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
[self configureView]; // Update the view
}
}
- (void)configureView
{
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad
{
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
[self configureView];
}
@end

View File

@ -6,8 +6,5 @@
// Copyright (c) 2014 conopsys. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface COSMasterViewController : UITableViewController
@end

View File

@ -7,105 +7,67 @@
//
#import "COSMasterViewController.h"
#import "COSDetailViewController.h"
@interface COSMasterViewController () {
NSMutableArray *_objects;
NSMutableArray* _objects;
}
@end
@implementation COSMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
UIBarButtonItem* addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)didReceiveMemoryWarning
{
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
- (void)insertNewObject:(id)sender {
if (!_objects) _objects = [NSMutableArray new];
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[ indexPath ] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
return _objects.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
NSDate* object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
- (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView deleteRowsAtIndexPaths:@[ indexPath ] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow];
NSDate* object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}