Created
February 6, 2010 11:39
-
-
Save nestserau/296666 to your computer and use it in GitHub Desktop.
Простое введение в компонентно-ориентированное программирование под iPhone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@class SCViewSlider; | |
@interface MainController : UIViewController { | |
@private | |
SCViewSlider *_viewSlider; | |
} | |
@property (nonatomic, retain) IBOutlet SCViewSlider *viewSlider; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation MainController | |
@synthesize viewSlider = _viewSlider; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.viewSlider.hideKeyboardOnReturn = YES; | |
self.viewSlider.ySlideDistance = 70.0f; | |
} | |
- (void)dealloc { | |
[_viewSlider release]; | |
[super dealloc]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
typedef enum { | |
SCSlideDirectionUp, | |
SCSlideDirectionDown | |
} SCSlideDirection; | |
@interface SCViewSlider : NSObject<UITextFieldDelegate> { | |
@private | |
UIView *_viewToSlide; | |
CGFloat _ySlideDistance; | |
CGFloat _heightSlideDistance; | |
CGFloat _slideDuration; | |
BOOL _hideKeyboardOnReturn; | |
} | |
@property (nonatomic, retain) IBOutlet UIView *viewToSlide; | |
@property (nonatomic, assign) CGFloat ySlideDistance; | |
@property (nonatomic, assign) CGFloat heightSlideDistance; | |
@property (nonatomic, assign) CGFloat slideDuration; | |
@property (nonatomic, assign) BOOL hideKeyboardOnReturn; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SCViewSlider.h" | |
@interface SCViewSlider (/* Private methods */) | |
- (void)slideTableView:(SCSlideDirection)direction; | |
@end | |
@implementation SCViewSlider | |
@synthesize viewToSlide = _viewToSlide; | |
@synthesize ySlideDistance = _ySlideDistance, heightSlideDistance = _heightSlideDistance, slideDuration = _slideDuration; | |
@synthesize hideKeyboardOnReturn = _hideKeyboardOnReturn; | |
- (id)init { | |
if (self = [super init]) { | |
_slideDuration = 0.3f; | |
} | |
return self; | |
} | |
- (void)dealloc { | |
[_viewToSlide release]; | |
[super dealloc]; | |
} | |
#pragma mark TextField Callbacks | |
- (void)textFieldDidBeginEditing:(UITextField *)textField { | |
[self slideTableView:SCSlideDirectionUp]; | |
} | |
- (void)textFieldDidEndEditing:(UITextField *)textField { | |
[self slideTableView:SCSlideDirectionDown]; | |
} | |
- (BOOL)textFieldShouldReturn:(UITextField *)textField { | |
if (self.hideKeyboardOnReturn) { | |
[textField resignFirstResponder]; | |
} | |
return YES; | |
} | |
- (void)slideTableView:(C7SlideDirection)direction { | |
CGFloat y = SCSlideDirectionUp == direction ? -self.ySlideDistance : self.ySlideDistance; | |
CGFloat height = SCSlideDirectionUp == direction ? -self.heightSlideDistance : self.heightSlideDistance; | |
CGRect rect = self.viewToSlide.frame; | |
rect = CGRectMake(rect.origin.x, rect.origin.y + y, rect.size.width, rect.size.height + height); | |
[UIView beginAnimations:@"SCViewSlider::slideView" context:nil]; | |
[UIView setAnimationBeginsFromCurrentState:YES]; | |
[UIView setAnimationDuration:self.slideDuration]; | |
self.viewToSlide.frame = rect; | |
[UIView commitAnimations]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment