Created
April 25, 2016 13:42
-
-
Save zonble/1d3cb2331abe216f23ae6685d79a6ea4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// CustomNVToolBarVC.m | |
// customToolBar | |
// | |
#import "CustomNVToolBarVC.h" | |
#import <objc/runtime.h> | |
@interface UIToolbar (Override) | |
@property (strong, nonnull, nonatomic) UIView *targetView; | |
@end | |
@implementation UIToolbar (Override) | |
- (void)setTargetView:(UIView *)targetView | |
{ | |
objc_setAssociatedObject(self, "targetView", targetView, OBJC_ASSOCIATION_RETAIN); | |
} | |
- (UIView *)targetView | |
{ | |
return objc_getAssociatedObject(self, "targetView"); | |
} | |
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event | |
{ | |
CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self]; | |
if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) { | |
return [self.targetView hitTest:pointForTargetView withEvent:event]; | |
} | |
return [super hitTest:point withEvent:event]; | |
} | |
@end | |
@interface CustomNVToolBarVC () | |
@property UIView * subView ; | |
@property UIButton * subButton; | |
- (void) pressed; | |
@end | |
@implementation CustomNVToolBarVC | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
self.subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | |
self.subView.backgroundColor = [UIColor blueColor]; | |
self.subButton = [[UIButton alloc]initWithFrame:CGRectMake(0 ,0 ,50 ,50)]; | |
self.subButton.backgroundColor = [UIColor greenColor]; | |
[self.subButton setTitle:@"Press" forState:UIControlStateNormal]; | |
[self.subButton addTarget:self action:@selector(pressed) forControlEvents:UIControlEventTouchUpInside]; | |
[self.subView addSubview:self.subButton]; | |
[self.toolbar addSubview:self.subView]; | |
self.toolbar.targetView = self.subView; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
-(void)pressed { | |
NSLog(@"pressed"); | |
[UIView animateWithDuration:0.5 animations:^{ | |
self.subView.frame = CGRectMake(0, -100, 100, 100); | |
}]; | |
} | |
/* | |
#pragma mark - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
// Get the new view controller using [segue destinationViewController]. | |
// Pass the selected object to the new view controller. | |
} | |
*/ | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment