text
stringlengths
9
39.2M
dir
stringlengths
26
295
lang
stringclasses
185 values
created_date
timestamp[us]
updated_date
timestamp[us]
repo_name
stringlengths
1
97
repo_full_name
stringlengths
7
106
star
int64
1k
183k
len_tokens
int64
1
13.8M
```objective-c // // YFAnimationVC04.m // BigShow1949 // // Created by WangMengqi on 15/9/2. // #import "YFAnimationVC04.h" @interface YFAnimationVC04 () @property (nonatomic, strong) YFRadialMenu *radialView; @end @implementation YFAnimationVC04 - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; } -(void) viewWillAppear:(BOOL)animated { } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; YFRadialMenu *radialView = [[YFRadialMenu alloc] initWithFrame:CGRectMake(self.view.center.x-25, self.view.frame.size.height - 120, 50, 50)]; radialView.delegate = self; radialView.centerView.backgroundColor = [UIColor grayColor]; [radialView addPopoutView:nil withIndentifier:@"ONE"]; [radialView addPopoutView:nil withIndentifier:@"TWO"]; [radialView addPopoutView:nil withIndentifier:@"THREE"]; [radialView addPopoutView:nil withIndentifier:@"FOUR"]; self.radialView = radialView; [self.view addSubview:radialView]; [radialView enableDevelopmentMode:self]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.radialView removeFromSuperview]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)radialMenu:(YFRadialMenu *)radialMenu didSelectPopoutWithIndentifier:(NSString *)identifier{ NSLog(@"%@",identifier); } @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/04 - RadialMenu/YFAnimationVC04.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
359
```objective-c // // YFContextMenuViewController.m // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import "YFContextMenuViewController.h" #import "ContextMenuCell.h" #import "YFContextMenuTableView.h" static NSString *const menuCellIdentifier = @"rotationCell"; @interface YFContextMenuViewController ()<UITableViewDataSource,UITableViewDelegate,YFContextMenuTableViewDelegate> @property (nonatomic, strong) YFContextMenuTableView *contextMenuTableView; @property (nonatomic, strong) NSArray *menuTitles; @property (nonatomic, strong) NSArray *menuIcons; @end @implementation YFContextMenuViewController - (void)viewDidLoad { [super viewDidLoad]; [self initiateMenuOptions]; [self initNav]; self.view.backgroundColor = [UIColor blueColor]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - UITableViewDataSource & UITableViewDelegate - (void)tableView:(YFContextMenuTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView dismisWithIndexPath:indexPath]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 65; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.menuTitles.count; } - (UITableViewCell *)tableView:(YFContextMenuTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ContextMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:menuCellIdentifier forIndexPath:indexPath]; if (cell) { cell.menuTitleLabel.text = [self.menuTitles objectAtIndex:indexPath.row]; cell.menuImageView.image = [self.menuIcons objectAtIndex:indexPath.row]; } return cell; } #pragma mark - private - (void)initiateMenuOptions { self.menuTitles = @[@"", @"Send message", @"Like profile", @"Add to friends", @"Add to favourites", @"Block user"]; self.menuIcons = @[[UIImage imageNamed:@"Icnclose"], [UIImage imageNamed:@"SendMessageIcn"], [UIImage imageNamed:@"LikeIcn"], [UIImage imageNamed:@"AddToFriendsIcn"], [UIImage imageNamed:@"AddToFavouritesIcn"], [UIImage imageNamed:@"BlockUserIcn"]]; } - (void)initNav { self.title = @""; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(menuClick)]; } - (void)menuClick { [self.contextMenuTableView showInView:self.navigationController.view withEdgeInsets:UIEdgeInsetsZero animated:YES]; } #pragma mark - - (YFContextMenuTableView *)contextMenuTableView { if (!_contextMenuTableView) { _contextMenuTableView = [[YFContextMenuTableView alloc] initWithTableViewDelegateDataSource:self]; _contextMenuTableView.animationDuration = 0.1; _contextMenuTableView.delegate = self; //register nib UINib *cellNib = [UINib nibWithNibName:@"ContextMenuCell" bundle:nil]; [_contextMenuTableView registerNib:cellNib forCellReuseIdentifier:menuCellIdentifier]; } return _contextMenuTableView; } @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenuViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
644
```objective-c // // YFContextMenuViewController.h // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import <UIKit/UIKit.h> @interface YFContextMenuViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenuViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // UIView+YFConstraints.m // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import "UIView+YFConstraints.h" @implementation UIView (YFConstraints) - (void)addSubViewiew:(UIView *)view withSidesConstrainsInsets:(UIEdgeInsets)insets { NSParameterAssert(view); [view setTranslatesAutoresizingMaskIntoConstraints:NO]; [self addSubview:view]; [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:insets.top]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0 constant:insets.left]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:insets.bottom]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:insets.right]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenu/UIView+YFConstraints.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
309
```objective-c // // YFContextMenuTableView.h // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import <UIKit/UIKit.h> @class YFContextMenuTableView; @protocol YFContextMenuTableViewDelegate <NSObject> @optional - (void)contextMenuTableView:(YFContextMenuTableView *)contextMenuTableView didDismissWithIndexPath:(NSIndexPath *)indexPath; @end @interface YFContextMenuTableView : UITableView @property (nonatomic) CGFloat animationDuration; @property (nonatomic, copy) id<YFContextMenuTableViewDelegate>delegate; - (instancetype)initWithTableViewDelegateDataSource:(id<UITableViewDelegate, UITableViewDataSource>)delegateDataSource; - (void)showInView:(UIView *)superview withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated; - (void)dismisWithIndexPath:(NSIndexPath *)indexPath; - (void)updateAlongsideRotation; @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenu/YFContextMenuTableView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
184
```objective-c // // YFContextMenuCell.h // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import <Foundation/Foundation.h> @protocol YFContextMenuCell <NSObject> - (UIView *)animatedIcon; - (UIView *)animatedContent; @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenu/YFContextMenuCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
65
```objective-c // // YFDragRadialMenu.m // BigShow1949 // // Created by WangMengqi on 15/9/2. // #import "YFDragRadialMenu.h" @interface YFDragRadialMenu() @property (nonatomic, assign) CGFloat maxW; @property (nonatomic, strong) NSMutableArray *elementsArray; // @end @implementation YFDragRadialMenu -(id)initWithFrame:(CGRect)frame{ return [self initFromPoint:CGPointZero withDataSource:nil andDelegate:nil]; } -(id)initFromPoint:(CGPoint)centerPoint withDataSource:(id<YFDragRadialMenuDataSource>)dataSource andDelegate:(id<YFDragRadialMenuDelegate>)delegate{ self = [super initWithFrame:CGRectMake([[UIScreen mainScreen] applicationFrame].origin.x, [[UIScreen mainScreen] applicationFrame].origin.y, [[UIScreen mainScreen] applicationFrame].size.width, [[UIScreen mainScreen] applicationFrame].size.height)]; if(self){ centerPoint.y -= [[UIScreen mainScreen] applicationFrame].origin.y; // //Fix the center point in case it is too near the corners of the screen // if(CGRectContainsPoint(CGRectMake(0, 0, 70, 70), centerPoint) && !CGPointEqualToPoint(centerPoint, CGPointZero)){ // _centerPoint = CGPointMake(70, 70); // } else if(CGRectContainsPoint(CGRectMake(0, [[UIScreen mainScreen] applicationFrame].size.height-70, 70, 70), centerPoint)){ // _centerPoint = CGPointMake(70, [[UIScreen mainScreen] applicationFrame].size.height-70); // } else if(CGRectContainsPoint(CGRectMake([[UIScreen mainScreen] applicationFrame].size.width-70, 0, 70, 70), centerPoint)){ // _centerPoint = CGPointMake([[UIScreen mainScreen] applicationFrame].size.width-70, 70); // } else if(CGRectContainsPoint(CGRectMake([[UIScreen mainScreen] applicationFrame].size.width-70, [[UIScreen mainScreen] applicationFrame].size.height-70, 70, 70), centerPoint)){ // _centerPoint = CGPointMake([[UIScreen mainScreen] applicationFrame].size.width-70, [[UIScreen mainScreen] applicationFrame].size.height-70); // } else _centerPoint = CGPointEqualToPoint(centerPoint, CGPointZero) ? self.center : centerPoint; _dataSource = dataSource; _delegate = delegate; self.backgroundColor = [UIColor clearColor]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeRadialMenu:)]; [self addGestureRecognizer:tapGesture]; tapGesture.delegate = self; } return self; } -(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ BOOL should = YES; if([touch.view isKindOfClass:[UIButton class]]){ should = NO; } return should; } #pragma mark - closeRadialMenu -(void)closeRadialMenu:(UITapGestureRecognizer *)tapGesture{ if([tapGesture.view isEqual:self] && !CGRectContainsPoint(self.radialMenuView.frame, [tapGesture locationInView:self])){ [self closeMenu]; } } -(void)closeMenu { [self closeMenuWithCompletion:nil]; } -(void)closeMenuWithCompletion:(void(^)())completion{ for(int i = 0; i < [self.elementsArray count]; i++){ UIButton *element = [self.elementsArray objectAtIndex:i]; double delayInSeconds = 0.025*i; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [UIView animateWithDuration:0.25 animations:^{ element.alpha = 0; element.center = CGPointMake(self.radialMenuView.frame.size.width/2.0, self.radialMenuView.frame.size.height/2.0); }]; }); } double delayInSeconds = 0.25+0.025*[self.elementsArray count]; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [UIView animateWithDuration:0.25 animations:^{ self.radialMenuView.alpha = 0; self.alpha = 0; } completion:^(BOOL finished) { [self.radialMenuView removeFromSuperview]; [self removeFromSuperview]; if(completion) completion(); }]; }); } #pragma mark - showMenu -(void) showMenu{ [self showMenuWithCompletion:nil]; } -(void)showMenuWithCompletion:(void (^)())completion{ // , view self.centerRadialView; [[[[UIApplication sharedApplication] delegate] window] addSubview:self]; [UIView animateWithDuration:0.25 animations:^{ self.backgroundColor = self.dimBackgroundColor; } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 animations:^{ if(self.centerRadialView){ CGFloat centerViewRadius = 7.0 * self.menuRadius/10.0; self.centerRadialView.layer.cornerRadius = centerViewRadius; self.centerRadialView.layer.masksToBounds = YES; self.centerRadialView.frame = CGRectMake(self.radialMenuView.frame.size.width/2.0 - centerViewRadius, self.radialMenuView.frame.size.height/2.0 - centerViewRadius, centerViewRadius*2.0, centerViewRadius*2.0); } } completion:^(BOOL finished) { [self placeRadialMenuElementsAnimated:YES]; if(completion) completion(); }]; }]; } -(void)placeRadialMenuElementsAnimated:(BOOL)animated{ CGFloat startingAngle = 0; CGFloat usableAngle = 2.0*M_PI; BOOL fullCircle = YES; // , , , CGFloat radiusToAdd = 0; //LEFT BORDER if(self.radialMenuView.frame.origin.x < 0){ fullCircle = NO; //BEGIN if(self.radialMenuView.frame.origin.y >0){ CGFloat d = -(self.radialMenuView.frame.origin.x +self.menuRadius); startingAngle = -acosf((d+5)/(self.menuRadius +radiusToAdd)); } else { CGFloat d = -(self.radialMenuView.frame.origin.y +self.menuRadius); startingAngle = asinf((d+self.maxW/2.0+5)/(self.menuRadius+radiusToAdd)); } //END if(CGRectGetMaxY(self.radialMenuView.frame) <= self.frame.size.height){ if(self.radialMenuView.frame.origin.y >0){ usableAngle = -2*startingAngle; } else { CGFloat d = -(self.radialMenuView.frame.origin.x +self.menuRadius); CGFloat virtualAngle = acosf((d+5)/(self.menuRadius+radiusToAdd)); usableAngle = 2*virtualAngle -(virtualAngle+startingAngle); } } else { CGFloat d = (CGRectGetMaxY(self.radialMenuView.frame)-self.frame.size.height -self.menuRadius); CGFloat virtualAngle = -asinf((d+5)/(self.menuRadius+radiusToAdd)); usableAngle = -startingAngle+virtualAngle; } } //TOP BORDER if(self.radialMenuView.frame.origin.y < 0 && self.radialMenuView.frame.origin.x > 0 && CGRectGetMaxX(self.radialMenuView.frame) < self.frame.size.width){ fullCircle = NO; CGFloat d = -(self.radialMenuView.frame.origin.y +self.menuRadius); startingAngle = asinf((d+self.maxW/2.0+5)/(self.menuRadius+radiusToAdd)); usableAngle = M_PI-2*startingAngle; } //BOTTOM BORDER if(CGRectGetMaxY(self.radialMenuView.frame) > self.frame.size.height && self.radialMenuView.frame.origin.x > 0 && CGRectGetMaxX(self.radialMenuView.frame) < self.frame.size.width){ fullCircle = NO; CGFloat d = (CGRectGetMaxY(self.radialMenuView.frame)-self.frame.size.height -self.menuRadius); startingAngle = M_PI+asinf((d+5)/(self.menuRadius+radiusToAdd)); usableAngle = 2*M_PI-startingAngle-asinf((d+5)/(self.menuRadius+radiusToAdd)); } //RIGHT BORDER if(CGRectGetMaxX(self.radialMenuView.frame) > self.frame.size.width){ fullCircle = NO; //BEGIN if(CGRectGetMaxY(self.radialMenuView.frame) < self.frame.size.height){ CGFloat d = self.menuRadius-(CGRectGetMaxX(self.radialMenuView.frame)-self.frame.size.width); startingAngle = acosf((d-5)/(self.menuRadius +radiusToAdd)); } else { CGFloat d = (CGRectGetMaxY(self.radialMenuView.frame)-self.frame.size.height -self.menuRadius); startingAngle = M_PI+asinf((d+5)/(self.menuRadius+radiusToAdd)); } //END if(self.radialMenuView.frame.origin.y > 0){ CGFloat d = self.menuRadius-(CGRectGetMaxX(self.radialMenuView.frame)-self.frame.size.width); CGFloat virtualAngle = acosf((d-5)/(self.menuRadius +radiusToAdd)); usableAngle = 2*M_PI-virtualAngle-startingAngle; } else { CGFloat d = -(self.radialMenuView.frame.origin.y +self.menuRadius); CGFloat virtualAngle = asinf((d+self.maxW/2.0+5)/(self.menuRadius+radiusToAdd)); usableAngle = M_PI-virtualAngle-startingAngle; } } //Placing the objects for(int i = 0; i < [self.elementsArray count]; i++){ UIButton *element = [self.elementsArray objectAtIndex:i]; element.center = CGPointMake(self.radialMenuView.frame.size.width/2.0, self.radialMenuView.frame.size.height/2.0); double delayInSeconds = 0.025 * i; void (^elementPositionBlock)(void) = ^{ element.alpha = 1; [self.radialMenuView bringSubviewToFront:element]; CGPoint endPoint = CGPointMake(self.radialMenuView.frame.size.width/2.0+(self.menuRadius+radiusToAdd)*(cos(startingAngle+usableAngle/(self.numberOfButtons - (fullCircle ? 0 :1))*(float)i)), self.radialMenuView.frame.size.height/2.0 + (self.menuRadius+radiusToAdd) * (sin(startingAngle+usableAngle/(self.numberOfButtons-(fullCircle ? 0 :1)) * (float)i))); element.center = endPoint; }; if(animated) { dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [UIView animateWithDuration:0.25 animations:elementPositionBlock]; }); } else { elementPositionBlock(); } } } -(void)moveAround:(UIPanGestureRecognizer *)panGesture{ if ((panGesture.state == UIGestureRecognizerStateChanged) || (panGesture.state == UIGestureRecognizerStateEnded)) { CGPoint translation = [panGesture translationInView:self]; // move something in myself (Im a UIView) by translation.x and translation.y // for example, if I were a graph and my origin was set by an @property called origin self.origin = CGPointMake(self.origin.x+translation.x, self.origin.y+translation.y); CGRect radialMenuRect = self.radialMenuView.frame; radialMenuRect.origin.x += translation.x; radialMenuRect.origin.y += translation.y; self.radialMenuView.frame = radialMenuRect; [self placeRadialMenuElementsAnimated:NO]; [panGesture setTranslation:CGPointZero inView:self]; } } -(void)didTapButton:(UIButton *)sender{ [self.delegate radialMenu:self didSelectButton:sender]; } #pragma mark - -(UIColor *) dimBackgroundColor{ if(!_dimBackgroundColor){ _dimBackgroundColor = [UIColor colorWithWhite:0 alpha:0.3]; } return _dimBackgroundColor; } - (UIView *)radialMenuView { if (!_radialMenuView) { _radialMenuView = [[UIView alloc] init]; _radialMenuView.frame = CGRectMake(0, 0, self.menuRadius * 2.0 + self.maxW, self.menuRadius * 2.0 + self.maxW); _radialMenuView.center = _centerPoint; _radialMenuView.userInteractionEnabled = YES; [self addSubview:self.radialMenuView]; // UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveAround:)]; panGesture.delegate = self; if([self.dataSource respondsToSelector:@selector(canDragRadialMenu:)]){ panGesture.enabled = [self.dataSource canDragRadialMenu:self]; } [_radialMenuView addGestureRecognizer:panGesture]; // RadialMenuView if([self.dataSource respondsToSelector:@selector(radialMenu:customizationForRadialMenuView:)]){ [self.dataSource radialMenu:self customizationForRadialMenuView:_radialMenuView]; } } return _radialMenuView; } - (NSMutableArray *)elementsArray { if (!_elementsArray) { _elementsArray = [[NSMutableArray alloc] init]; self.maxW = 0; for(int i = 0; i < self.numberOfButtons; i++){ UIButton *element = [self.dataSource radialMenu:self elementAtIndex:i]; if(self.maxW < element.frame.size.width) self.maxW = element.frame.size.width; element.userInteractionEnabled = YES; element.alpha = 0; element.tag = i; [element addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; [_elementsArray addObject:element]; [self.radialMenuView addSubview:element]; } } return _elementsArray; } - (UIView *)centerRadialView { if (!_centerRadialView) { if([self.dataSource respondsToSelector:@selector(viewForCenterOfRadialMenu:)]){ _centerRadialView = [self.dataSource viewForCenterOfRadialMenu:self]; if(_centerRadialView){ _centerRadialView.frame = CGRectZero; _centerRadialView.center = CGPointMake(self.radialMenuView.frame.size.width/2.0, self.radialMenuView.frame.size.height/2.0); [self.radialMenuView addSubview:_centerRadialView]; } } } return _centerRadialView; } - (NSInteger)numberOfButtons { if (!_numberOfButtons) { _numberOfButtons = [self.dataSource numberOfButtonsForRadialMenu:self]; } return _numberOfButtons; } - (CGFloat)menuRadius { if (!_menuRadius) { if(self.dataSource && [self.dataSource respondsToSelector:@selector(radiusLenghtForRadialMenu:)]){ _menuRadius = [self.dataSource radiusLenghtForRadialMenu:self]; }else { _menuRadius = 60; } } return _menuRadius; } @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/06 - DragRadialMenu/YFDragRadialMenu.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
3,329
```objective-c // // UIView+YFConstraints.h // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import <UIKit/UIKit.h> @interface UIView (YFConstraints) - (void)addSubViewiew:(UIView *)view withSidesConstrainsInsets:(UIEdgeInsets)insets; @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenu/UIView+YFConstraints.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
77
```objective-c // // ContextMenuCell.m // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import "ContextMenuCell.h" @interface ContextMenuCell () @end @implementation ContextMenuCell - (void)awakeFromNib { [super awakeFromNib]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.layer.masksToBounds = YES; self.layer.shadowOffset = CGSizeMake(0, 2); self.layer.shadowColor = [[UIColor colorWithRed:181.0/255.0 green:181.0/255.0 blue:181.0/255.0 alpha:1] CGColor]; self.layer.shadowRadius = 5; self.layer.shadowOpacity = 0.5; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } #pragma mark - YALContextMenuCell - (UIView*)animatedIcon { return self.menuImageView; } - (UIView *)animatedContent { return self.menuTitleLabel; } @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/ContextMenuCell/ContextMenuCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
219
```objective-c // // ContextMenuCell.h // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import <UIKit/UIKit.h> #import "YFContextMenuCell.h" @interface ContextMenuCell : UITableViewCell<YFContextMenuCell> @property (strong, nonatomic) IBOutlet UIImageView *menuImageView; @property (strong, nonatomic) IBOutlet UILabel *menuTitleLabel; @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/ContextMenuCell/ContextMenuCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
87
```objective-c // // YFContextMenuTableView.m // BigShow1949 // // Created by WangMengqi on 15/9/1. // #import "YFContextMenuTableView.h" #import "YFContextMenuCell.h" #import "UIView+YFConstraints.h" #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) static CGFloat const defaultDuration = 0.3; static CGPoint const defaultViewAnchorPoint = {0.5f, 0.5f}; typedef void(^completionBlock)(BOOL completed); typedef NS_ENUM(NSUInteger, Direction) { right, top, bottom }; typedef NS_ENUM(NSUInteger, AnimatingState) { Hiding = -1, Stable = 0, Showing = 1 }; @interface YFContextMenuTableView () @property (nonatomic) __block NSInteger animatingIndex; @property (nonatomic, strong) NSMutableArray *topCells; @property (nonatomic, strong) NSMutableArray *bottomCells; @property (nonatomic, strong) UITableViewCell<YFContextMenuCell> *selectedCell; @property (nonatomic, strong) NSIndexPath *dismissalIndexpath; @property (nonatomic) AnimatingState animatingState; @end @implementation YFContextMenuTableView #pragma mark - Init - (instancetype)initWithTableViewDelegateDataSource:(id<UITableViewDelegate, UITableViewDataSource>)delegateDataSource { self = [self init]; if (self) { // self.delegate = delegateDataSource; self.dataSource = delegateDataSource; } return self; } - (instancetype)init { self = [super init]; if (self) { self.animatingState = Stable; self.animationDuration = defaultDuration; self.animatingIndex = 0; self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7f]; self.separatorColor = [UIColor colorWithRed:181.0/255.0 green:181.0/255.0 blue:181.0/255.0 alpha:0]; self.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //Zero rect footer to clear empty rows UITableView draws } return self; } #pragma mark - Show / Dismiss - (void)showInView:(UIView *)superview withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated { if (self.animatingState!=Stable) { return; } for (UITableViewCell<YFContextMenuCell> *aCell in [self visibleCells]) { aCell.contentView.hidden = YES; } self.dismissalIndexpath = nil; [superview addSubViewiew:self withSidesConstrainsInsets:edgeInsets]; if (animated) { self.animatingState = Showing; self.alpha = 0; [self setUserInteractionEnabled:NO]; [UIView animateWithDuration:self.animationDuration animations:^{ self.alpha = 1; } completion:^(BOOL finished) { [self show:YES visibleCellsAnimated:YES]; [self setUserInteractionEnabled:YES]; }]; } else { [self show:YES visibleCellsAnimated:NO]; } } - (void)dismisWithIndexPath:(NSIndexPath *)indexPath { if (self.animatingState!=Stable) { return; } if (!indexPath) { [self removeFromSuperview]; return; } self.dismissalIndexpath = indexPath; self.animatingState = Hiding; [self setUserInteractionEnabled:NO]; NSArray *visibleCells = [self visibleCells]; self.topCells = [NSMutableArray array]; self.bottomCells = [NSMutableArray array]; for (UITableViewCell<YFContextMenuCell> *visibleCell in visibleCells) { if ([self indexPathForCell:visibleCell].row<indexPath.row) { [self.topCells addObject: visibleCell]; } else if ([self indexPathForCell:visibleCell].row>indexPath.row) { [self.bottomCells addObject: visibleCell]; } else { self.selectedCell = visibleCell; } } [self dismissTopCells]; [self dismissBottomCells]; } - (void)updateAlongsideRotation { if (self.animatingState == Hiding) { if ([self.delegate respondsToSelector:@selector(contextMenuTableView:didDismissWithIndexPath:)]) { [self.delegate contextMenuTableView:self didDismissWithIndexPath:[self indexPathForCell:self.selectedCell]]; } [self removeFromSuperview]; } else if (self.animatingState == Showing) { [self show:YES visibleCellsAnimated:NO]; } self.animatingState = Stable; } #pragma mark - Private - (void)show:(BOOL)show visibleCellsAnimated:(BOOL)animated { NSArray *visibleCells = [self visibleCells]; if (visibleCells.count == 0 || self.animatingIndex == visibleCells.count) { self.animatingIndex = 0; [self setUserInteractionEnabled:YES]; [self reloadData]; self.animatingState = Stable; return; } UITableViewCell<YFContextMenuCell> *visibleCell = [visibleCells objectAtIndex:self.animatingIndex]; if (visibleCell) { [self prepareCellForShowAnimation:visibleCell]; [visibleCell contentView].hidden = NO; Direction direction = ([visibleCells indexOfObject:visibleCell] == 0) ? right : top; [self show:show cell:visibleCell animated:animated direction:direction clockwise:NO completion:^(BOOL completed) { if (completed) { self.animatingIndex++; [self show:show visibleCellsAnimated:animated]; } }]; } } - (void)dismissBottomCells { if (self.bottomCells.count) { UITableViewCell<YFContextMenuCell> *hidingCell = [self.bottomCells lastObject]; [self show:NO cell:hidingCell animated:YES direction:top clockwise:NO completion:^(BOOL completed) { if (completed) { [self.bottomCells removeLastObject]; [self dismissBottomCells]; [self shouldDismissSelf]; } }]; } } - (void)dismissTopCells { if (self.topCells.count) { UITableViewCell<YFContextMenuCell> *hidingCell = [self.topCells firstObject]; [self show:NO cell:hidingCell animated:YES direction:bottom clockwise:YES completion:^(BOOL completed) { if (completed) { [self.topCells removeObjectAtIndex:0]; [self dismissTopCells]; [self shouldDismissSelf]; } }]; } } - (void)dismissSelf { [self show:NO cell:self.selectedCell animated:YES direction:right clockwise:NO completion:^(BOOL completed) { [self removeFromSuperview]; if ([self.delegate respondsToSelector:@selector(contextMenuTableView:didDismissWithIndexPath:)]) { [self.delegate contextMenuTableView:self didDismissWithIndexPath:[self indexPathForCell:self.selectedCell]]; } self.animatingState = Stable; }]; } - (void)shouldDismissSelf { if (self.bottomCells.count == 0 && self.topCells.count == 0) { [self dismissSelf]; } } #pragma mark - Animate Cells - (void)prepareCellForShowAnimation:(UITableViewCell<YFContextMenuCell> *)cell { [self resetAnimatedIconForCell:cell]; Direction direction = ([self indexPathForCell:cell].row == 0) ? right : top; [self show:NO cell:cell animated:NO direction:direction clockwise:NO completion:nil]; } /*! @abstract Call this method for cell view to be hidden or shown @param show - YES to be shown, NO to be hidden @param animated - Yes or NO for animation @param animation - Duration of animation with seconds @param direction - Define the side for icon to animate @param clockwise - Set YES to rotate clockwise @param completed - block called on the completion of the animation */ - (void)show:(BOOL)show cell:(UITableViewCell<YFContextMenuCell> *)cell animated:(BOOL)animated direction:(Direction)direction clockwise:(BOOL)clockwise completion:(completionBlock)completed { UIView *icon = [cell animatedIcon]; UIView *content = [cell animatedContent]; CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity; rotationAndPerspectiveTransform.m34 = 1.0/200; //Add the perspective CGFloat rotation = 90; if (clockwise) { rotation = -rotation; } if (show) { rotation = 0; } switch (direction) { case right: { [self setAnchorPoint:CGPointMake(1, 0.5) forView:icon]; rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, DEGREES_TO_RADIANS(rotation), 0.0f, 1.0f, 0.0f); break; } case top: { [self setAnchorPoint:CGPointMake(0.5, 0.0) forView:icon]; rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, DEGREES_TO_RADIANS(rotation), 1.0f, 0.0f, 0.0f); break; } case bottom: { [self setAnchorPoint:CGPointMake(0.5, 1) forView:icon]; rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, DEGREES_TO_RADIANS(rotation), 1.0f, 0.0f, 0.0f); break; } default: break; } if (animated) { [UIView animateWithDuration:self.animationDuration animations:^{ icon.layer.transform = rotationAndPerspectiveTransform; content.alpha = show; } completion:^(BOOL finished) { if (completed) { completed(finished); } }]; } else { icon.layer.transform = rotationAndPerspectiveTransform; content.alpha = show; if (completed) { completed(YES); } } } #pragma mark - Overriden - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { UITableViewCell<YFContextMenuCell> *cell = [super dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; [self resetAnimatedIconForCell:cell]; if (cell) { if (self.animatingState==Showing) { [cell contentView].hidden = YES; }else if (self.animatingState==Stable) { [cell contentView].hidden = NO; [cell animatedContent].alpha = 1; } } return cell; } #pragma mark - Utils - (void)resetAnimatedIconForCell:(UITableViewCell<YFContextMenuCell> *) cell{ UIView *icon = [cell animatedIcon]; icon.layer.anchorPoint = defaultViewAnchorPoint; icon.layer.transform = CATransform3DIdentity; [icon layoutIfNeeded]; } - (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view { CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); // NSLog(@"anchorPoint = %@", NSStringFromCGPoint(anchorPoint)); NSLog(@"newPoint = %@", NSStringFromCGPoint(newPoint)); CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); // NSLog(@"view.layer.anchorPoint = %@", NSStringFromCGPoint(view.layer.anchorPoint)); NSLog(@"oldPoint = %@", NSStringFromCGPoint(oldPoint)); NSLog(@"newPoint transform = %@", NSStringFromCGPoint(newPoint)); newPoint = CGPointApplyAffineTransform(newPoint, view.transform); NSLog(@"newPoint transform = %@", NSStringFromCGPoint(newPoint)); oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); CGPoint position = view.layer.position; position.x -= oldPoint.x; position.x += newPoint.x; position.y -= oldPoint.y; position.y += newPoint.y; view.layer.position = position; view.layer.anchorPoint = anchorPoint; } @end ```
/content/code_sandbox/BigShow1949/Classes/07 - Animations(动画)/01 - 弹出菜单/01 - ContextMenu/YFContextMenu/YFContextMenuTableView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,598
```objective-c // // YFUIKitViewController.h // BigShow1949 // // Created by apple on 16/8/20. // #import "BaseTableViewController.h" @interface YFUIKitViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/YFUIKitViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // YFUIKitViewController.m // BigShow1949 // // Created by apple on 16/8/20. // #import "YFUIKitViewController.h" @interface YFUIKitViewController () @end @implementation YFUIKitViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"Tabbar",@"YFKnowledgeVC02"], @[@"UIScrollView",@"YFScrollViewController"], @[@"SearchController",@"YFSearchController"], @[@"UIDynamic",@"YFDynamicViewController"], @[@"UICollectionView",@"YFCollectionViewController"],]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/YFUIKitViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
130
```objective-c // // YFDynamicViewController.m // BigShow1949 // // Created by zhht01 on 16/8/24. // #import "YFDynamicViewController.h" @interface YFDynamicViewController () @end @implementation YFDynamicViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"",@"YFCollisionBehaviorViewController_UIStoryboard"], @[@"",@"YFSnapBehaviorViewController"], @[@"",@"YFPushBehaviorViewController"], @[@"",@"YFAttachmentBehaviorViewController"], @[@"",@"YFDynamicItemViewController"], @[@"()",@"YFFlexViewController"], @[@"(CADisplayLink)",@"UINTViewController"],]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/YFDynamicViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
151
```objective-c // // YFDynamicViewController.h // BigShow1949 // // Created by zhht01 on 16/8/24. // #import "BaseTableViewController.h" @interface YFDynamicViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/YFDynamicViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
53
```objective-c // // YFAttachmentBehaviorViewController.h // BigShow1949 // // Created by apple on 16/8/25. // #import <UIKit/UIKit.h> @interface YFAttachmentBehaviorViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/附着行为/YFAttachmentBehaviorViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // YFFlexView.h // BigShow1949 // // Created by apple on 16/8/25. // #import <UIKit/UIKit.h> @class DraggableView; @class PaneBehavior; typedef NS_ENUM(NSInteger, PaneState) { PaneStateOpen, PaneStateClosed, }; @interface YFFlexView : UIView @property (nonatomic, readonly) PaneState paneState; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/YFFlexView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
89
```objective-c // // Created by Florian on 02/05/14. // // To change the template use AppCode | Preferences | File Templates. // #import "PaneBehavior.h" @interface PaneBehavior () @property (nonatomic, strong) UIAttachmentBehavior *attachmentBehavior; @property (nonatomic, strong) UIDynamicItemBehavior *itemBehavior; @property (nonatomic, strong) id <UIDynamicItem> item; @end @implementation PaneBehavior - (instancetype)initWithItem:(id <UIDynamicItem>)item { self = [super init]; if (self) { self.item = item; [self setup]; } return self; } - (void)setup { UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.item attachedToAnchor:CGPointZero]; attachmentBehavior.frequency = 3.5; attachmentBehavior.damping = .4; attachmentBehavior.length = 0; [self addChildBehavior:attachmentBehavior]; self.attachmentBehavior = attachmentBehavior; UIDynamicItemBehavior *itemBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.item]]; itemBehavior.density = 100; itemBehavior.resistance = 10; [self addChildBehavior:itemBehavior]; self.itemBehavior = itemBehavior; } - (void)setTargetPoint:(CGPoint)targetPoint { _targetPoint = targetPoint; self.attachmentBehavior.anchorPoint = targetPoint; } - (void)setVelocity:(CGPoint)velocity { _velocity = velocity; CGPoint currentVelocity = [self.itemBehavior linearVelocityForItem:self.item]; CGPoint velocityDelta = CGPointMake(velocity.x - currentVelocity.x, velocity.y - currentVelocity.y); [self.itemBehavior addLinearVelocity:velocityDelta forItem:self.item]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/PaneBehavior.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
370
```objective-c // // YFAttachmentBehaviorViewController.m // BigShow1949 // // Created by apple on 16/8/25. // #import "YFAttachmentBehaviorViewController.h" @interface YFAttachmentBehaviorViewController () @property (nonatomic, strong) UIView *square1; @property(nonatomic,strong)UIDynamicAnimator *animator; @property (nonatomic, strong) UIAttachmentBehavior *attachmentBehavior; @end @implementation YFAttachmentBehaviorViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // self.square1 =[[UIView alloc] initWithFrame: CGRectMake(0.0f, 568-80, 80.0f, 80.0f)]; self.square1.backgroundColor = [UIColor greenColor]; self.square1.center = self.view.center; [self.view addSubview:self.square1]; self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; UICollisionBehavior* collision = [[UICollisionBehavior alloc] initWithItems:@[self.square1]]; collision.translatesReferenceBoundsIntoBoundary = YES; UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.square1]]; [self.animator addBehavior:collision]; [self.animator addBehavior:gravity]; // [self createGestureRecognizer]; } - (void)createGestureRecognizer{ UIPanGestureRecognizer *tapGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [self.view addGestureRecognizer:tapGestureRecognizer]; } - (void)handleTap:(UIPanGestureRecognizer *)gesture{ if (gesture.state == UIGestureRecognizerStateBegan){ NSLog(@"----Began"); CGPoint squareCenterPoint = CGPointMake(self.square1.center.x, self.square1.center.y - 100.0); UIAttachmentBehavior* attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 attachedToAnchor:squareCenterPoint]; self.attachmentBehavior = attachmentBehavior; [self.animator addBehavior:attachmentBehavior]; } else if ( gesture.state == UIGestureRecognizerStateChanged) { NSLog(@"----Changed"); [self.attachmentBehavior setAnchorPoint:[gesture locationInView:self.view]]; } else if (gesture.state == UIGestureRecognizerStateEnded) { NSLog(@"----Ended"); [self.animator removeBehavior:self.attachmentBehavior]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/附着行为/YFAttachmentBehaviorViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
511
```objective-c // // Created by Florian on 21/04/14. // // To change the template use AppCode | Preferences | File Templates. // #import <Foundation/Foundation.h> @class DraggableView; @protocol DraggableViewDelegate - (void)draggableView:(DraggableView *)view draggingEndedWithVelocity:(CGPoint)velocity; - (void)draggableViewBeganDragging:(DraggableView *)view; @end @interface DraggableView : UIView @property (nonatomic, weak) id <DraggableViewDelegate> delegate; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/DraggableView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
110
```objective-c // // YFFlexView.m // BigShow1949 // // Created by apple on 16/8/25. // #import "YFFlexView.h" #import "DraggableView.h" #import "PaneBehavior.h" @interface YFFlexView ()<DraggableViewDelegate> @property (nonatomic) PaneState paneState; @property (nonatomic) DraggableView *pane; @property (nonatomic) UIDynamicAnimator *animator; @property (nonatomic, strong) PaneBehavior *paneBehavior; @end @implementation YFFlexView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } - (void)setup { self.backgroundColor = [UIColor whiteColor]; CGSize size = self.bounds.size; self.paneState = PaneStateClosed; self.pane = [[DraggableView alloc] initWithFrame:CGRectMake(0, size.height * .75, size.width, size.height)]; self.pane.backgroundColor = [UIColor grayColor]; self.pane.layer.cornerRadius = 8; self.pane.delegate = self; [self addSubview:self.pane]; self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self]; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)]; [self addGestureRecognizer:tapRecognizer]; } - (void)animatePaneWithInitialVelocity:(CGPoint)initialVelocity { if (!self.paneBehavior) { PaneBehavior *behavior = [[PaneBehavior alloc] initWithItem:self.pane]; self.paneBehavior = behavior; } self.paneBehavior.targetPoint = self.targetPoint; self.paneBehavior.velocity = initialVelocity; [self.animator addBehavior:self.paneBehavior]; } - (CGPoint)targetPoint { CGSize size = self.bounds.size; return self.paneState == PaneStateClosed > 0 ? CGPointMake(size.width/2, size.height * 1.25) : CGPointMake(size.width/2, size.height/2 + 100); } #pragma mark DraggableViewDelegate - (void)draggableView:(DraggableView *)view draggingEndedWithVelocity:(CGPoint)velocity { PaneState targetState = velocity.y >= 0 ? PaneStateClosed : PaneStateOpen; self.paneState = targetState; [self animatePaneWithInitialVelocity:velocity]; } - (void)draggableViewBeganDragging:(DraggableView *)view { [self.animator removeAllBehaviors]; } #pragma mark Actions - (void)didTap:(UITapGestureRecognizer *)tapRecognizer { self.paneState = self.paneState == PaneStateOpen ? PaneStateClosed : PaneStateOpen; [self animatePaneWithInitialVelocity:self.paneBehavior.velocity]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/YFFlexView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
600
```objective-c // // YFFlexViewController.m // BigShow1949 // // Created by apple on 16/8/25. // #import "YFFlexViewController.h" #import "YFFlexView.h" @implementation YFFlexViewController - (void)viewDidLoad { [super viewDidLoad]; YFFlexView *flexView = [[YFFlexView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:flexView]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/YFFlexViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
97
```objective-c // // YFFlexViewController.h // BigShow1949 // // Created by apple on 16/8/25. // #import <UIKit/UIKit.h> @interface YFFlexViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/YFFlexViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
48
```objective-c // // Created by Florian on 02/05/14. // // To change the template use AppCode | Preferences | File Templates. // #import <Foundation/Foundation.h> @interface PaneBehavior : UIDynamicBehavior @property (nonatomic) CGPoint targetPoint; @property (nonatomic) CGPoint velocity; - (instancetype)initWithItem:(id <UIDynamicItem>)item; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/PaneBehavior.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
74
```objective-c // // // : // #import "YFSnapBehaviorViewController.h" @interface YFSnapBehaviorViewController() @property(nonatomic,strong)UIDynamicAnimator *animator; @property (nonatomic, strong) UIButton *blueView; @end @implementation YFSnapBehaviorViewController -(void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; UIButton *blueView = [[UIButton alloc] init]; blueView.frame = CGRectMake(100, 100, 100, 100); blueView.backgroundColor = [UIColor blueColor]; [self.view addSubview:blueView]; self.blueView = blueView; } -(UIDynamicAnimator *)animator { if (_animator==nil) { //ReferenceView _animator=[[UIDynamicAnimator alloc]initWithReferenceView:self.view]; } return _animator; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // UITouch *touch=[touches anyObject]; CGPoint point=[touch locationInView:touch.view]; //1. // UISnapBehavior *snap=[[UISnapBehavior alloc]initWithItem:self.blueView snapToPoint:point]; //0~1 snap.damping=arc4random_uniform(10)/10.0; //2. // // [self.animator removeAllBehaviors]; [self.animator addBehavior:snap]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/捕捉行为/YFSnapBehaviorViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
301
```objective-c // // Created by Florian on 21/04/14. // // To change the template use AppCode | Preferences | File Templates. // #import "DraggableView.h" @implementation DraggableView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } - (void)setup { UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)]; [self addGestureRecognizer:recognizer]; } - (void)didPan:(UIPanGestureRecognizer *)recognizer { CGPoint point = [recognizer translationInView:self.superview]; self.center = CGPointMake(self.center.x, self.center.y + point.y); [recognizer setTranslation:CGPointZero inView:self.superview]; if (recognizer.state == UIGestureRecognizerStateEnded) { CGPoint velocity = [recognizer velocityInView:self.superview]; velocity.x = 0; [self.delegate draggableView:self draggingEndedWithVelocity:velocity]; } else if (recognizer.state == UIGestureRecognizerStateBegan) { [self.delegate draggableViewBeganDragging:self]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(附着行为)/DraggableView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
253
```objective-c // // YFSnapBehaviorViewController.h // BigShow1949 // // Created by apple on 16/8/25. // #import <UIKit/UIKit.h> @interface YFSnapBehaviorViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/捕捉行为/YFSnapBehaviorViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // UINTViewController.h // InteractiveAnimations // // Created by Chris Eidhof on 02.05.14. // #import <UIKit/UIKit.h> @class UINTAnimator; @class UINTSpringAnimation; @interface UINTViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
53
```objective-c @protocol Animation <NSObject> - (void)animationTick:(CFTimeInterval)dt finished:(BOOL *)finished; @end @interface Animator : NSObject + (instancetype)animatorWithScreen:(UIScreen *)screen; - (void)addAnimation:(id<Animation>)animatable; - (void)removeAnimation:(id<Animation>)animatable; @end @interface UIView (AnimatorAdditions) - (Animator *)animator; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/Animator.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
89
```objective-c // // Created by Florian on 21/04/14. // // To change the template use AppCode | Preferences | File Templates. // #import "UINTDraggableView.h" @implementation UINTDraggableView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } - (void)setup { UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)]; [self addGestureRecognizer:recognizer]; self.layer.cornerRadius = 6; } - (void)didPan:(UIPanGestureRecognizer *)recognizer { CGPoint point = [recognizer translationInView:self.superview]; self.center = CGPointMake(self.center.x, self.center.y + point.y); [recognizer setTranslation:CGPointZero inView:self.superview]; if (recognizer.state == UIGestureRecognizerStateEnded) { CGPoint velocity = [recognizer velocityInView:self.superview]; velocity.x = 0; [self.delegate draggableView:self draggingEndedWithVelocity:velocity]; } else if (recognizer.state == UIGestureRecognizerStateBegan) { [self.delegate draggableViewBeganDragging:self]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTDraggableView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
264
```objective-c // // Created by chris on 02.05.14. // #import "UINTSpringAnimation.h" #import "UINTGeometryExtras.h" @interface UINTSpringAnimation () @property (nonatomic) CGPoint velocity; @property (nonatomic) CGPoint targetPoint; @property (nonatomic) UIView *view; @end @implementation UINTSpringAnimation - (instancetype)initWithView:(UIView *)view target:(CGPoint)target velocity:(CGPoint)velocity { self = [super init]; if (self) { self.view = view; self.targetPoint = target; self.velocity = velocity; } return self; } + (instancetype)animationWithView:(UIView *)view target:(CGPoint)target velocity:(CGPoint)velocity { return [[self alloc] initWithView:view target:target velocity:velocity]; } - (void)animationTick:(CFTimeInterval)dt finished:(BOOL *)finished { static const float frictionConstant = 20; static const float springConstant = 300; CGFloat time = (CGFloat) dt; // friction force = velocity * friction constant // = * CGPoint frictionForce = CGPointMultiply(self.velocity, frictionConstant); // spring force = (target point - current position) * spring constant // = ( - ) * CGPoint springForce = CGPointMultiply(CGPointSubtract(self.targetPoint, self.view.center), springConstant); // force = spring force - friction force // = - CGPoint force = CGPointSubtract(springForce, frictionForce); // velocity = current velocity + force * time / mass // = + * / self.velocity = CGPointAdd(self.velocity, CGPointMultiply(force, time)); // position = current position + velocity * time // = + * self.view.center = CGPointAdd(self.view.center, CGPointMultiply(self.velocity, time)); CGFloat speed = CGPointLength(self.velocity); CGFloat distanceToGoal = CGPointLength(CGPointSubtract(self.targetPoint, self.view.center)); if (speed < 0.05 && distanceToGoal < 1) { self.view.center = self.targetPoint; *finished = YES; } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTSpringAnimation.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
464
```objective-c // // Created by Florian on 21/04/14. // // To change the template use AppCode | Preferences | File Templates. // #import <Foundation/Foundation.h> #import "Animator.h" @class UINTDraggableView; @protocol DraggableViewDelegate - (void)draggableView:(UINTDraggableView *)view draggingEndedWithVelocity:(CGPoint)velocity; - (void)draggableViewBeganDragging:(UINTDraggableView *)view; @end @interface UINTDraggableView : UIView @property (nonatomic, weak) id <DraggableViewDelegate> delegate; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTDraggableView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
119
```objective-c // // UINTAppDelegate.h // InteractiveAnimations // // Created by Chris Eidhof on 02.05.14. // #import <UIKit/UIKit.h> @interface UINTAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTAppDelegate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
56
```objective-c // // UINTViewController.m // InteractiveAnimations // // Created by Chris Eidhof on 02.05.14. // #import "UINTViewController.h" #import "DraggableView.h" #import "UINTSpringAnimation.h" typedef NS_ENUM(NSInteger, PaneState) { PaneStateOpen, PaneStateClosed, }; @interface UINTViewController () <DraggableViewDelegate> @property (nonatomic) PaneState paneState; @property (nonatomic, strong) DraggableView *pane; @property (nonatomic) UINTSpringAnimation *springAnimation; @end @implementation UINTViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; CGSize size = self.view.bounds.size; self.paneState = PaneStateClosed; DraggableView *view = [[DraggableView alloc] initWithFrame:CGRectMake(0, size.height * .75, size.width, size.height)]; view.backgroundColor = [UIColor grayColor]; view.delegate = self; [self.view addSubview:view]; self.pane = view; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)]; [self.view addGestureRecognizer:tapRecognizer]; } - (CGPoint)targetPoint { CGSize size = self.view.bounds.size; CGPoint targetPoint = self.paneState == PaneStateClosed > 0 ? CGPointMake(size.width/2, size.height * 1.25) : CGPointMake(size.width/2, size.height/2 + 100); return targetPoint; } - (void)startAnimatingView:(DraggableView *)view initialVelocity:(CGPoint)initialVelocity { [self cancelSpringAnimation]; self.springAnimation = [UINTSpringAnimation animationWithView:view target:self.targetPoint velocity:initialVelocity]; [view.animator addAnimation:self.springAnimation]; } - (void)cancelSpringAnimation { [self.view.animator removeAnimation:self.springAnimation]; self.springAnimation = nil; } #pragma mark DraggableViewDelegate - (void)draggableView:(DraggableView *)view draggingEndedWithVelocity:(CGPoint)velocity { PaneState targetState = velocity.y >= 0 ? PaneStateClosed : PaneStateOpen; self.paneState = targetState; [self startAnimatingView:view initialVelocity:velocity]; } - (void)draggableViewBeganDragging:(DraggableView *)view { [self cancelSpringAnimation]; } #pragma mark Actions - (void)didTap:(UITapGestureRecognizer *)tapRecognizer { PaneState targetState = self.paneState == PaneStateOpen ? PaneStateClosed : PaneStateOpen; self.paneState = targetState; [self startAnimatingView:self.pane initialVelocity:self.springAnimation.velocity]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
577
```objective-c // // UINTAppDelegate.m // InteractiveAnimations // // Created by Chris Eidhof on 02.05.14. // #import "UINTAppDelegate.h" #import "UINTViewController.h" @implementation UINTAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UINTViewController *viewController = [[UINTViewController alloc] init]; self.window.rootViewController = viewController; [self.window makeKeyAndVisible]; return YES; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTAppDelegate.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
117
```objective-c // // Created by chris on 02.05.14. // #import <Foundation/Foundation.h> static inline CGPoint CGPointSubtract(CGPoint p1, CGPoint p2) { return CGPointMake(p1.x - p2.x, p1.y - p2.y); } static inline CGPoint CGPointAdd(CGPoint p1, CGPoint p2) { return CGPointMake(p1.x + p2.x, p1.y + p2.y); } static inline CGPoint CGPointMultiply(CGPoint point, CGFloat multiplier) { return CGPointMake(point.x * multiplier, point.y * multiplier); } static inline CGFloat CGPointLength(CGPoint point) { return (CGFloat)sqrt(point.x * point.x + point.y * point.y); } ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTGeometryExtras.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
151
```objective-c // // Created by chris on 02.05.14. // #import <Foundation/Foundation.h> #import "Animator.h" @interface UINTSpringAnimation : NSObject <Animation> @property (nonatomic, readonly) CGPoint velocity; + (instancetype)animationWithView:(UIView *)view target:(CGPoint)target velocity:(CGPoint)velocity; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTSpringAnimation.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
69
```objective-c #import "Animator.h" #import <objc/runtime.h> static int ScreenAnimationDriverKey; @interface Animator () @property (nonatomic, strong) CADisplayLink *displayLink; @property (nonatomic, strong) NSMutableSet *animations; @end @implementation Animator { } + (instancetype)animatorWithScreen:(UIScreen *)screen { if (!screen) { screen = [UIScreen mainScreen]; } Animator *driver = objc_getAssociatedObject(screen, &ScreenAnimationDriverKey); if (!driver) { driver = [[self alloc] initWithScreen:screen]; objc_setAssociatedObject(screen, &ScreenAnimationDriverKey, driver, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return driver; } - (instancetype)initWithScreen:(UIScreen *)screen { self = [super init]; if (self) { self.displayLink = [screen displayLinkWithTarget:self selector:@selector(animationTick:)]; self.displayLink.paused = YES; [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; self.animations = [NSMutableSet new]; } return self; } - (void)addAnimation:(id<Animation>)animation { [self.animations addObject:animation]; if (self.animations.count == 1) { self.displayLink.paused = NO; } } - (void)removeAnimation:(id <Animation>)animatable { if (animatable == nil) return; [self.animations removeObject:animatable]; if (self.animations.count == 0) { self.displayLink.paused = YES; } } - (void)animationTick:(CADisplayLink *)displayLink { CFTimeInterval dt = displayLink.duration; for (id<Animation> a in [self.animations copy]) { BOOL finished = NO; [a animationTick:dt finished:&finished]; if (finished) { [self.animations removeObject:a]; } } if (self.animations.count == 0) { self.displayLink.paused = YES; } } @end @implementation UIView (AnimatorAdditions) - (Animator *)animator { return [Animator animatorWithScreen:self.window.screen]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/弹簧效果(CADisplayLink)/Animator.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
463
```objective-c // // YYViewController.m // 12- // // Created by apple on 14-8-6. // #import "YFCollisionBehaviorViewController.h" @interface YFCollisionBehaviorViewController () @property (weak, nonatomic) IBOutlet UIView *redView; @property (weak, nonatomic) IBOutlet UIProgressView *block1; @property (weak, nonatomic) IBOutlet UISegmentedControl *block2; @property(nonatomic,strong)UIDynamicAnimator *animator; @end @implementation YFCollisionBehaviorViewController -(UIDynamicAnimator *)animator { if (_animator==nil) { //ReferenceView: self.animator=[[UIDynamicAnimator alloc]initWithReferenceView:self.view]; } return _animator; } - (void)viewDidLoad { [super viewDidLoad]; //view self.redView.transform=CGAffineTransformMakeRotation(M_PI_4); } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //1. // [self testGravity]; //2.+ // [self testGravityAndCollsion]; //3. [self testGravityAndCollsion2]; //2 // [self testGravityAndCollision3]; //4. // [self testGravityAndCollision4]; } /** * */ -(void)testGravity { //1. // UIGravityBehavior *gravity=[[UIGravityBehavior alloc] init]; //2. [gravity addItem:self.redView]; //3. [self.animator addBehavior:gravity]; } /** * + */ -(void)testGravityAndCollsion { //1. UIGravityBehavior *gravity=[[UIGravityBehavior alloc]init]; [gravity addItem:self.redView]; //2 UICollisionBehavior *collision=[[UICollisionBehavior alloc]init]; [collision addItem:self.redView]; [collision addItem:self.block1]; [collision addItem:self.block2]; // collision.translatesReferenceBoundsIntoBoundary=YES; //3. [self.animator addBehavior:gravity]; [self.animator addBehavior:collision]; } /** * */ -(void)testGravityAndCollsion2 { //1. UIGravityBehavior *gravity=[[UIGravityBehavior alloc]init]; //1 // gravity.angle=(M_PI_2-M_PI_4); //2, gravity.magnitude=1000; //3 gravity.gravityDirection=CGVectorMake(0, 1); [gravity addItem:self.redView]; //2 UICollisionBehavior *collision=[[UICollisionBehavior alloc]init]; [collision addItem:self.redView]; [collision addItem:self.block1]; [collision addItem:self.block2]; // collision.translatesReferenceBoundsIntoBoundary=YES; //3. [self.animator addBehavior:gravity]; [self.animator addBehavior:collision]; } /** * */ - (void)testGravityAndCollision4 { // 1. UIGravityBehavior *gravity = [[UIGravityBehavior alloc] init]; [gravity addItem:self.redView]; // [gravity addItem:self.block1]; // [gravity addItem:self.block2]; // 2. UICollisionBehavior *collision = [[UICollisionBehavior alloc] init]; [collision addItem:self.redView]; [collision addItem:self.block1]; [collision addItem:self.block2]; // UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 320, 320)]; [collision addBoundaryWithIdentifier:@"circle" forPath:path]; // 3. [self.animator addBehavior:gravity]; [self.animator addBehavior:collision]; } /** * 2 */ - (void)testGravityAndCollision3 { // 1. UIGravityBehavior *gravity = [[UIGravityBehavior alloc] init]; [gravity addItem:self.redView]; // 2. UICollisionBehavior *collision = [[UICollisionBehavior alloc] init]; [collision addItem:self.redView]; [collision addItem:self.block1]; [collision addItem:self.block2]; CGPoint startP = CGPointMake(0, 160); CGPoint endP = CGPointMake(320, 568); [collision addBoundaryWithIdentifier:@"line1" fromPoint:startP toPoint:endP]; CGPoint startP1 = CGPointMake(320, 0); [collision addBoundaryWithIdentifier:@"line2" fromPoint:startP1 toPoint:endP]; // collision.translatesReferenceBoundsIntoBoundary = YES; // 3. [self.animator addBehavior:gravity]; [self.animator addBehavior:collision]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/碰撞检测/YFCollisionBehaviorViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,031
```objective-c // // YYViewController.h // Test // // Created by zhht01 on 16/8/24. // #import <UIKit/UIKit.h> @interface YFCollisionBehaviorViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/碰撞检测/YFCollisionBehaviorViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // YFPushBehaviorViewController.h // BigShow1949 // // Created by apple on 16/8/25. // #import <UIKit/UIKit.h> @interface YFPushBehaviorViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/推动行为/YFPushBehaviorViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // YFPushBehaviorViewController.m // BigShow1949 // // Created by apple on 16/8/25. // #import "YFPushBehaviorViewController.h" @interface YFPushBehaviorViewController () @property(nonatomic,strong)UIDynamicAnimator *animator; @property (nonatomic, strong) UIView *squareView; @property (nonatomic, strong) UIPushBehavior *pushBehavior; @end @implementation YFPushBehaviorViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; // self.squareView =[[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 80.0f, 80.0f)]; self.squareView.backgroundColor = [UIColor greenColor]; self.squareView.center = self.view.center; [self.view addSubview:self.squareView]; // [self createGestureRecognizer]; [self createAnimatorAndBehaviors]; } - (void) createGestureRecognizer{ UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [self.view addGestureRecognizer:tapGestureRecognizer]; } - (void) handleTap:(UITapGestureRecognizer *)paramTap{ CGPoint tapPoint = [paramTap locationInView:self.view]; //p2 CGPoint squareViewCenterPoint = self.squareView.center; //p1 CGFloat deltaX = tapPoint.x - squareViewCenterPoint.x; CGFloat deltaY = tapPoint.y - squareViewCenterPoint.y; CGFloat angle = atan2(deltaY, deltaX); [self.pushBehavior setAngle:angle]; // // CGFloat distanceBetweenPoints = sqrt(pow(tapPoint.x - squareViewCenterPoint.x, 2.0) + pow(tapPoint.y - squareViewCenterPoint.y, 2.0)); //double pow(double x, double y;xy //double sqrt (double); // [self.pushBehavior setMagnitude:distanceBetweenPoints / 50.0f]; //1magnigude100/ } - (void) createSmallSquareView{ self.squareView =[[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 80.0f, 80.0f)]; self.squareView.backgroundColor = [UIColor greenColor]; self.squareView.center = self.view.center; [self.view addSubview:self.squareView]; } - (void) createAnimatorAndBehaviors{ self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; /* Create collision detection */ UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[self.squareView]]; collision.translatesReferenceBoundsIntoBoundary = YES; self.pushBehavior = [[UIPushBehavior alloc] initWithItems:@[self.squareView] mode:UIPushBehaviorModeContinuous]; [self.animator addBehavior:collision]; [self.animator addBehavior:self.pushBehavior]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/推动行为/YFPushBehaviorViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
659
```objective-c // // YFDynamicItemViewController.m // BigShow1949 // // Created by apple on 16/8/25. // #import "YFDynamicItemViewController.h" @interface YFDynamicItemViewController () @property(nonatomic,strong)UIDynamicAnimator *animator; @property (nonatomic, strong) UIView *redView; @end @implementation YFDynamicItemViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; UIView *redView = [[UIView alloc] init]; redView.frame = CGRectMake(100, 100, 100, 100); redView.backgroundColor = [UIColor redColor]; self.redView = redView; [self.view addSubview:redView]; } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self testGravityAndCollsion]; } /** * + */ -(void)testGravityAndCollsion { //1. UIGravityBehavior *gravity=[[UIGravityBehavior alloc]init]; [gravity addItem:self.redView]; //2 UICollisionBehavior *collision=[[UICollisionBehavior alloc]init]; [collision addItem:self.redView]; // collision.translatesReferenceBoundsIntoBoundary=YES; // UIDynamicItemBehavior * itemBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.redView]]; itemBehavior.elasticity = 1; // 1 itemBehavior.friction = 5; itemBehavior.density = 10; itemBehavior.resistance = 3; // ,, itemBehavior.allowsRotation = NO; itemBehavior.angularResistance = 1; /* * : * path_to_url */ //3. [self.animator addBehavior:gravity]; [self.animator addBehavior:collision]; [self.animator addBehavior:itemBehavior]; } -(UIDynamicAnimator *)animator { if (_animator==nil) { //ReferenceView: self.animator=[[UIDynamicAnimator alloc]initWithReferenceView:self.view]; } return _animator; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/动力元素行为/YFDynamicItemViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
461
```objective-c // // YFDynamicItemViewController.h // BigShow1949 // // Created by apple on 16/8/25. // #import <UIKit/UIKit.h> @interface YFDynamicItemViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIDynamic/动力元素行为/YFDynamicItemViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // YFSearchController.h // BigShow1949 // // Created by zhht01 on 16/1/15. // #import <UIKit/UIKit.h> @interface YFSearchController : UITableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UISearchController/YFSearchController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // SearchResultsViewController.m // UISearchController // // Created by zhht-2015 on 16/1/14. // #import "SearchResultsViewController.h" @interface SearchResultsViewController () @end @implementation SearchResultsViewController - (void)viewDidLoad { [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = NO; self.tableView.tableFooterView = [[UIView alloc] init]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.searchDataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath]; cell.textLabel.text = [self.searchDataArray objectAtIndex:indexPath.row]; return cell; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [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; } */ /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UISearchController/SearchResultsViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
545
```objective-c // // SearchResultsViewController.h // UISearchController // // Created by zhht-2015 on 16/1/14. // #import <UIKit/UIKit.h> @interface SearchResultsViewController : UITableViewController @property (nonatomic, strong) NSMutableArray *searchDataArray; // @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UISearchController/SearchResultsViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
63
```objective-c // // YFSearchController.m // BigShow1949 // // Created by zhht01 on 16/1/15. // #import "YFSearchController.h" #import "SearchResultsViewController.h" @interface YFSearchController ()<UISearchResultsUpdating> @property (nonatomic, strong) NSMutableArray *dataArray; @property (nonatomic, strong) UISearchController *searchController; @end @implementation YFSearchController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"UISearchController"; self.tableView.tableFooterView = [[UIView alloc] init]; NSArray *array = @[@"1FUGC", @"2U6GC", @"3U7GC", @"4GFD", @"5DSAY", @"6ASD", @"7QWE", @"8RTY", @"9PDF", @"10MNB", @"VCXZ", @"LKJH"]; self.dataArray = [NSMutableArray arrayWithArray:array]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; self.tableView.tableHeaderView = self.searchController.searchBar; self.searchController.searchResultsUpdater = self; } - (UISearchController *)searchController { if (!_searchController) { SearchResultsViewController *searchResultsViewController = [[SearchResultsViewController alloc] init]; _searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsViewController]; // nil _searchController.searchBar.frame = CGRectMake(0, 0, 200, 44); _searchController.searchBar.placeholder = @""; } return _searchController; } #pragma mark - UISearchResultsUpdating - (void)updateSearchResultsForSearchController:(UISearchController *)searchController { // NSMutableArray *tempArray = [NSMutableArray array]; NSString *text = searchController.searchBar.text; for (NSString *item in self.dataArray) { if (text.length != 0 && [item containsString:text]) { [tempArray addObject:item]; } } // searchResultViewControllerreloadData SearchResultsViewController *searchResultsViewController = (SearchResultsViewController *)searchController.searchResultsController; searchResultsViewController.tableView.frame = CGRectMake(0, 64, YFScreen.width, YFScreen.height - 64); searchResultsViewController.searchDataArray = [NSMutableArray arrayWithArray:tempArray]; [searchResultsViewController.tableView reloadData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; cell.textLabel.text = self.dataArray[indexPath.row]; return cell; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UISearchController/YFSearchController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
628
```objective-c // // YFKnowledgeVC02.h // BigShow1949 // // Created by on 15-9-5. // #import <UIKit/UIKit.h> @interface YFKnowledgeVC02 : UITabBarController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/YFKnowledgeVC02.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // SYTabBar.m // 31.3 - // // Created by apple on 15-3-6. // #import "SYTabBar.h" #import "SYTabButton.h" @interface SYTabBar () @property (nonatomic, assign) UIButton *selectButton; @end @implementation SYTabBar + (instancetype)tabBar { SYTabBar *tabBar = [[SYTabBar alloc] init]; return tabBar; } - (void)addTabBarButtonWithItem:(UITabBarItem *)item { UIButton *button = [SYTabButton buttonWithType:UIButtonTypeCustom]; button.tag = self.subviews.count; [button setBackgroundImage:item.image forState:UIControlStateNormal]; [button setBackgroundImage:item.selectedImage forState:UIControlStateSelected]; if (self.subviews.count) { [self btnClick:button]; } [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown]; [self addSubview:button]; } // - (void)btnClick:(UIButton *)button { self.selectButton.selected = NO; button.selected = YES; self.selectButton = button; // if ([_delegate respondsToSelector:@selector(tabBar:didSelectIndex:)]) { // [_delegate tabBar:self didSelectIndex:button.tag]; // } if (_tabBarBlock) { _tabBarBlock(button.tag); } } - (void)layoutSubviews { [super layoutSubviews]; NSUInteger count = self.subviews.count; for (NSUInteger i = 0; i < count; i++) { UIButton *btn = self.subviews[i]; CGFloat btnW = self.bounds.size.width / count; CGFloat btnH = self.bounds.size.height; CGFloat btnX = i * btnW; btn.frame = CGRectMake(btnX, 0, btnW, btnH); } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Model/SYTabBar.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
394
```objective-c // // YFKnowledgeVC02.m // BigShow1949 // // Created by on 15-9-5. // #import "YFKnowledgeVC02.h" #import "SYHallViewController.h" #import "SYArenaViewController.h" #import "SYDiscoverViewController.h" #import "SYHistoryViewController.h" #import "SYMineViewController.h" #import "SYTabBar.h" @interface YFKnowledgeVC02 () @property (nonatomic, weak) SYTabBar *customTabBar; @end @implementation YFKnowledgeVC02 - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.title = @"bug"; // 1.tabBar [self setUpTabBar]; // 2.tabBarButton [self setUpAllChildViewController]; // self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(leftClick)]; } // 1.tabBar - (void)setUpTabBar { SYTabBar *myTabBar = [[SYTabBar alloc] init]; // myTabBar.delegate = self; myTabBar.tabBarBlock = ^(NSInteger selIndex){ self.selectedIndex = selIndex; }; self.customTabBar = myTabBar; myTabBar.frame = self.tabBar.frame; [self.view addSubview:myTabBar]; [self.tabBar removeFromSuperview]; } // 2.tabBarButton - (void)setUpAllChildViewController { // SYHallViewController *hall = [[SYHallViewController alloc] init]; [self setUpOneChileViewController:hall imageName:@"TabBar_LotteryHall_new" selImageName:@"TabBar_LotteryHall_selected_new" title:@""]; // SYArenaViewController *arena = [[SYArenaViewController alloc] init]; [self setUpOneChileViewController:arena imageName:@"TabBar_Arena_new" selImageName:@"TabBar_Arena_selected_new" title:@""]; // SYDiscoverViewController *dis = [[SYDiscoverViewController alloc] init]; [self setUpOneChileViewController:dis imageName:@"TabBar_Discovery_new" selImageName:@"TabBar_Discovery_selected_new" title:@""]; // SYHistoryViewController *history = [[SYHistoryViewController alloc] init]; [self setUpOneChileViewController:history imageName:@"TabBar_History_new" selImageName:@"TabBar_History_selected_new" title:@""]; // SYMineViewController *mine = [[SYMineViewController alloc] init]; [self setUpOneChileViewController:mine imageName:@"TabBar_MyLottery_new" selImageName:@"TabBar_MyLottery_selected_new" title:@""]; } - (void)setUpOneChileViewController:(UIViewController *)vc imageName:(NSString *)imageName selImageName:(NSString *)selImageName title:(NSString *)title { vc.navigationItem.title = title;// bug vc.tabBarItem.image = [UIImage imageNamed:imageName]; vc.tabBarItem.selectedImage = [UIImage imageNamed:selImageName]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; [self addChildViewController:nav]; // [self.customTabBar addTabBarButtonWithItem:vc.tabBarItem]; } - (void)tabBar:(SYTabBar *)tabBar didSelectIndex:(NSUInteger)selIndex { self.selectedIndex = selIndex; } - (void)leftClick { [self dismissViewControllerAnimated:YES completion:nil]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/YFKnowledgeVC02.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
752
```objective-c // // SYTabButton.m // 31.3 - // // Created by apple on 15-3-6. // #import "SYTabButton.h" @implementation SYTabButton // : - (void)setHighlighted:(BOOL)highlighted { } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Model/SYTabButton.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
61
```objective-c // // SYTabButton.h // 31.3 - // // Created by apple on 15-3-6. // #import <UIKit/UIKit.h> @interface SYTabButton : UIButton @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Model/SYTabButton.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // SYTabBar.h // 31.3 - // // Created by apple on 15-3-6. // #import <UIKit/UIKit.h> //@class SYTabBar; //@protocol SYTabBarDelegate <NSObject> // //@optional //- (void)tabBar:(SYTabBar *)tabBar didSelectIndex:(NSUInteger)selIndex; // //@end typedef void(^SYTabBarBlock) (NSInteger selectedIndex); @interface SYTabBar : UIView //@property (nonatomic, weak) id<SYTabBarDelegate> delegate; @property (nonatomic, copy) SYTabBarBlock tabBarBlock; + (instancetype)tabBar; - (void)addTabBarButtonWithItem:(UITabBarItem *)item; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Model/SYTabBar.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
155
```objective-c // // SYHistoryViewController.m // 31.1-() // // Created by apple on 14-11-8. // #import "SYHistoryViewController.h" @interface SYHistoryViewController () @end @implementation SYHistoryViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYHistoryViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
161
```objective-c // // SYMineViewController.m // 31.1-() // // Created by apple on 14-11-8. // #import "SYMineViewController.h" @interface SYMineViewController () @end @implementation SYMineViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYMineViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
161
```objective-c // // SYArenaViewController.m // 31.1-() // // Created by apple on 14-11-8. // #import "SYArenaViewController.h" @interface SYArenaViewController () @end @implementation SYArenaViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYArenaViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
161
```objective-c // // SYDiscoverViewController.m // 31.1-() // // Created by apple on 14-11-8. // #import "SYDiscoverViewController.h" @interface SYDiscoverViewController () @end @implementation SYDiscoverViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYDiscoverViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
161
```objective-c // // SYHistoryViewController.h // 31.1-() // // Created by apple on 14-11-8. // #import <UIKit/UIKit.h> @interface SYHistoryViewController : UITableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYHistoryViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // SYHallViewController.m // 31.1-() // // Created by apple on 14-11-8. // #import "SYHallViewController.h" @interface SYHallViewController () @end @implementation SYHallViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYHallViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
161
```objective-c // // SYTabBarViewController.h // 31.3 - // // Created by apple on 15-3-7. // #import <UIKit/UIKit.h> @interface SYTabBarViewController : UITabBarController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYTabBarViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // SYArenaViewController.h // 31.1-() // // Created by apple on 14-11-8. // #import <UIKit/UIKit.h> @interface SYArenaViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYArenaViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // SYMineViewController.h // 31.1-() // // Created by apple on 14-11-8. // #import <UIKit/UIKit.h> @interface SYMineViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYMineViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // SYHallViewController.h // 31.1-() // // Created by apple on 14-11-8. // #import <UIKit/UIKit.h> @interface SYHallViewController : UITableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYHallViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // SYDiscoverViewController.h // 31.1-() // // Created by apple on 14-11-8. // #import <UIKit/UIKit.h> @interface SYDiscoverViewController : UITableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYDiscoverViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // SYTabBarViewController.m // 31.3 - // // Created by apple on 15-3-7. // #import "SYTabBarViewController.h" #import "SYHallViewController.h" #import "SYArenaViewController.h" #import "SYDiscoverViewController.h" #import "SYHistoryViewController.h" #import "SYMineViewController.h" #import "SYTabBar.h" //@interface SYTabBarViewController ()<SYTabBarDelegate> @interface SYTabBarViewController () @property (nonatomic, weak) SYTabBar *customTabBar; @end @implementation SYTabBarViewController - (void)viewDidLoad { [super viewDidLoad]; // 1.tabBar [self setUpTabBar]; // 2.tabBarButton [self setUpAllChildViewController]; } // 1.tabBar - (void)setUpTabBar { SYTabBar *myTabBar = [[SYTabBar alloc] init]; // myTabBar.delegate = self; myTabBar.tabBarBlock = ^(NSInteger selIndex){ self.selectedIndex = selIndex; }; self.customTabBar = myTabBar; myTabBar.frame = self.tabBar.frame; [self.view addSubview:myTabBar]; [self.tabBar removeFromSuperview]; } // 2.tabBarButton - (void)setUpAllChildViewController { // SYHallViewController *hall = [[SYHallViewController alloc] init]; [self setUpOneChileViewController:hall imageName:@"TabBar_LotteryHall_new" selImageName:@"TabBar_LotteryHall_selected_new" title:@""]; // SYArenaViewController *arena = [[SYArenaViewController alloc] init]; [self setUpOneChileViewController:arena imageName:@"TabBar_Arena_new" selImageName:@"TabBar_Arena_selected_new" title:@""]; // SYDiscoverViewController *dis = [[SYDiscoverViewController alloc] init]; [self setUpOneChileViewController:dis imageName:@"TabBar_Discovery_new" selImageName:@"TabBar_Discovery_selected_new" title:@""]; // SYHistoryViewController *history = [[SYHistoryViewController alloc] init]; [self setUpOneChileViewController:history imageName:@"TabBar_History_new" selImageName:@"TabBar_History_selected_new" title:@""]; // SYMineViewController *mine = [[SYMineViewController alloc] init]; [self setUpOneChileViewController:mine imageName:@"TabBar_MyLottery_new" selImageName:@"TabBar_MyLottery_selected_new" title:@""]; } - (void)setUpOneChileViewController:(UIViewController *)vc imageName:(NSString *)imageName selImageName:(NSString *)selImageName title:(NSString *)title { vc.navigationItem.title = title; vc.tabBarItem.image = [UIImage imageNamed:imageName]; vc.tabBarItem.selectedImage = [UIImage imageNamed:selImageName]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; [self addChildViewController:nav]; // [self.customTabBar addTabBarButtonWithItem:vc.tabBarItem]; } - (void)tabBar:(SYTabBar *)tabBar didSelectIndex:(NSUInteger)selIndex { self.selectedIndex = selIndex; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/Tabbar/Demo/Controller/SYTabBarViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
696
```objective-c // // YFCollectionViewController.m // BigShow1949 // // Created by apple on 16/9/7. // #import "YFCollectionViewController.h" @implementation YFCollectionViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"CollectionView",@"YFNormalCollectionViewController"], @[@"",@"YFHorizontalScrollViewController"], @[@"",@"YFWaterflowViewController"], @[@"RACollectionView",@"RAViewController_UIStoryboard"],]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/YFCollectionViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
111
```objective-c // // YFNormalCollectionViewController.h // BigShow1949 // // Created by apple on 16/9/22. // #import <UIKit/UIKit.h> @interface YFNormalCollectionViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/基础collectionView/YFNormalCollectionViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // YFCollectionViewController.h // BigShow1949 // // Created by apple on 16/9/7. // #import "BaseTableViewController.h" @interface YFCollectionViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/YFCollectionViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // RACollectionViewCell.h // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/27/14. // #import <UIKit/UIKit.h> @interface RACollectionViewCell : UICollectionViewCell @property (nonatomic, strong) UIImageView *imageView; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RACollectionViewCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
69
```objective-c // // YFNormalCollectionViewController.m // BigShow1949 // // Created by apple on 16/9/22. // #define randomColor [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1] #define YFScreen [UIScreen mainScreen].bounds.size #define screenHeight [[UIScreen mainScreen]bounds].size.height // #define screenWidth [[UIScreen mainScreen]bounds].size.width // #define colletionCell 3 // #import "YFNormalCollectionViewController.h" @interface YFNormalCollectionViewController ()<UICollectionViewDataSource,UICollectionViewDelegate> { // UICollectionView *collectionView; NSMutableArray *hArr; //cell } @property (nonatomic, strong) UICollectionView *collectionView; @end @implementation YFNormalCollectionViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; hArr = [[NSMutableArray alloc] init]; UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc]init]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; // self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, screenWidth ,screenHeight) collectionViewLayout:flowLayout]; self.collectionView.dataSource=self; self.collectionView.delegate=self; [self.collectionView setBackgroundColor:[UIColor clearColor]]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"]; [self.view addSubview:self.collectionView]; } #pragma mark --UICollectionViewDelegateFlowLayout //Item - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat height=100+(arc4random()%120); [hArr addObject:[NSString stringWithFormat:@"%f",height]]; return CGSizeMake(screenWidth/colletionCell-8, height); //cell } //UICollectionView margin -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0,0, 0, 0); } #pragma mark -- UICollectionViewDataSource //UICollectionViewCell -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 20; } //Section -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } //UICollectionView -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString * CellIdentifier = @"UICollectionViewCell"; UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; cell.backgroundColor = randomColor; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; label.textColor = [UIColor redColor]; label.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row]; //cell for (id subView in cell.contentView.subviews) { [subView removeFromSuperview]; } NSInteger remainder=indexPath.row%colletionCell; NSInteger currentRow=indexPath.row/colletionCell; CGFloat currentHeight=[hArr[indexPath.row] floatValue]; CGFloat positonX=(screenWidth/colletionCell-8)*remainder+5*(remainder+1); CGFloat positionY=(currentRow+1)*5; for (NSInteger i=0; i<currentRow; i++) { NSInteger position=remainder+i*colletionCell; positionY+=[hArr[position] floatValue]; } cell.frame = CGRectMake(positonX, positionY,screenWidth/colletionCell-8,currentHeight) ;//cell [cell.contentView addSubview:label]; // :cell, cell, return cell; } #pragma mark --UICollectionViewDelegate //UICollectionView -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; cell.backgroundColor = [UIColor greenColor]; } //UICollectionView -(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath { return YES; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/基础collectionView/YFNormalCollectionViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
862
```objective-c // // RAViewController.m // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/25/14. // #import "RAViewController.h" #import "RACollectionViewCell.h" @interface RAViewController () @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *photosArray; @end @implementation RAViewController - (void)viewDidLoad { [super viewDidLoad]; self.collectionView.delegate = self; self.collectionView.dataSource = self; [self setupPhotosArray]; } - (void)setupPhotosArray { [_photosArray removeAllObjects]; _photosArray = nil; _photosArray = [NSMutableArray array]; for (NSInteger i = 1; i <= 20; i++) { NSString *photoName = [NSString stringWithFormat:@"%ld.jpg",i]; UIImage *photo = [UIImage imageNamed:photoName]; [_photosArray addObject:photo]; } } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 2; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { if (section == 0) { return 1; } return _photosArray.count; } - (CGFloat)sectionSpacingForCollectionView:(UICollectionView *)collectionView { return 5.f; } - (CGFloat)minimumInteritemSpacingForCollectionView:(UICollectionView *)collectionView { return 5.f; } - (CGFloat)minimumLineSpacingForCollectionView:(UICollectionView *)collectionView { return 5.f; } - (UIEdgeInsets)insetsForCollectionView:(UICollectionView *)collectionView { return UIEdgeInsetsMake(5.f, 0, 5.f, 0); } - (CGSize)collectionView:(UICollectionView *)collectionView sizeForLargeItemsInSection:(NSInteger)section { if (section == 0) { return CGSizeMake(320, 200); } return RACollectionViewTripletLayoutStyleSquare; //same as default ! } - (UIEdgeInsets)autoScrollTrigerEdgeInsets:(UICollectionView *)collectionView { return UIEdgeInsetsMake(50.f, 0, 50.f, 0); //Sorry, horizontal scroll is not supported now. } - (UIEdgeInsets)autoScrollTrigerPadding:(UICollectionView *)collectionView { return UIEdgeInsetsMake(64.f, 0, 0, 0); } - (CGFloat)reorderingItemAlpha:(UICollectionView *)collectionview { return .3f; } - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath { [self.collectionView reloadData]; } - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath didMoveToIndexPath:(NSIndexPath *)toIndexPath { UIImage *image = [_photosArray objectAtIndex:fromIndexPath.item]; [_photosArray removeObjectAtIndex:fromIndexPath.item]; [_photosArray insertObject:image atIndex:toIndexPath.item]; } - (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath canMoveToIndexPath:(NSIndexPath *)toIndexPath { if (toIndexPath.section == 0) { return NO; } return YES; } - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { return NO; } return YES; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { static NSString *cellID = @"headerCell"; UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; return cell; }else { static NSString *cellID = @"cellID"; RACollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; [cell.imageView removeFromSuperview]; cell.imageView.frame = cell.bounds; cell.imageView.image = _photosArray[indexPath.item]; [cell.contentView addSubview:cell.imageView]; return cell; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { return; } if (_photosArray.count == 1) { return; } [self.collectionView performBatchUpdates:^{ [_photosArray removeObjectAtIndex:indexPath.item]; [self.collectionView deleteItemsAtIndexPaths:@[indexPath]]; } completion:^(BOOL finished) { [self.collectionView reloadData]; }]; } - (IBAction)refresh:(UIBarButtonItem *)sender { [self setupPhotosArray]; [self.collectionView reloadData]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RAViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
975
```objective-c // // RACollectionViewReorderableTripletLayout.h // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/27/14. // #import "RACollectionViewTripletLayout.h" @protocol RACollectionViewReorderableTripletLayoutDataSource <RACollectionViewTripletLayoutDatasource> @optional - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath; - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath didMoveToIndexPath:(NSIndexPath *)toIndexPath; - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath; - (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath canMoveToIndexPath:(NSIndexPath *)toIndexPath; @end @protocol RACollectionViewDelegateReorderableTripletLayout <RACollectionViewDelegateTripletLayout> @optional - (CGFloat)reorderingItemAlpha:(UICollectionView * )collectionview; //Default 0. - (UIEdgeInsets)autoScrollTrigerEdgeInsets:(UICollectionView *)collectionView; //Sorry, has not supported horizontal scroll. - (UIEdgeInsets)autoScrollTrigerPadding:(UICollectionView *)collectionView; - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath; - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath; - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath; - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath; @end @interface RACollectionViewReorderableTripletLayout : RACollectionViewTripletLayout <UIGestureRecognizerDelegate> @property (nonatomic, weak) id<RACollectionViewDelegateReorderableTripletLayout> delegate; @property (nonatomic, weak) id<RACollectionViewReorderableTripletLayoutDataSource> datasource; @property (nonatomic, strong, readonly) UILongPressGestureRecognizer *longPressGesture; @property (nonatomic, strong, readonly) UIPanGestureRecognizer *panGesture; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RACollectionViewReorderableTripletLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
476
```objective-c // // RACollectionViewReorderableTripletLayout.m // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/27/14. // #import "RACollectionViewReorderableTripletLayout.h" typedef NS_ENUM(NSInteger, RAScrollDirction) { RAScrollDirctionNone, RAScrollDirctionUp, RAScrollDirctionDown }; @interface UIImageView (RACollectionViewReorderableTripletLayout) - (void)setCellCopiedImage:(UICollectionViewCell *)cell; @end @implementation UIImageView (RACollectionViewReorderableTripletLayout) - (void)setCellCopiedImage:(UICollectionViewCell *)cell { UIGraphicsBeginImageContextWithOptions(cell.bounds.size, NO, 4.f); [cell.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.image = image; } @end @interface RACollectionViewReorderableTripletLayout() @property (nonatomic, strong) UIView *cellFakeView; @property (nonatomic, strong) CADisplayLink *displayLink; @property (nonatomic, assign) RAScrollDirction scrollDirection; @property (nonatomic, strong) NSIndexPath *reorderingCellIndexPath; @property (nonatomic, assign) CGPoint reorderingCellCenter; @property (nonatomic, assign) CGPoint cellFakeViewCenter; @property (nonatomic, assign) CGPoint panTranslation; @property (nonatomic, assign) UIEdgeInsets scrollTrigerEdgeInsets; @property (nonatomic, assign) UIEdgeInsets scrollTrigePadding; @property (nonatomic, assign) BOOL setUped; @end @implementation RACollectionViewReorderableTripletLayout #pragma mark - Override methods - (void)setDelegate:(id<RACollectionViewDelegateReorderableTripletLayout>)delegate { self.collectionView.delegate = delegate; } - (id<RACollectionViewDelegateReorderableTripletLayout>)delegate { return (id<RACollectionViewDelegateReorderableTripletLayout>)self.collectionView.delegate; } - (void)setDatasource:(id<RACollectionViewReorderableTripletLayoutDataSource>)datasource { self.collectionView.dataSource = datasource; } - (id<RACollectionViewReorderableTripletLayoutDataSource>)datasource { return (id<RACollectionViewReorderableTripletLayoutDataSource>)self.collectionView.dataSource; } - (void)prepareLayout { [super prepareLayout]; //gesture [self setUpCollectionViewGesture]; //scroll triger insets _scrollTrigerEdgeInsets = UIEdgeInsetsMake(50.f, 50.f, 50.f, 50.f); if ([self.delegate respondsToSelector:@selector(autoScrollTrigerEdgeInsets:)]) { _scrollTrigerEdgeInsets = [self.delegate autoScrollTrigerEdgeInsets:self.collectionView]; } //scroll triger padding _scrollTrigePadding = UIEdgeInsetsMake(0, 0, 0, 0); if ([self.delegate respondsToSelector:@selector(autoScrollTrigerPadding:)]) { _scrollTrigePadding = [self.delegate autoScrollTrigerPadding:self.collectionView]; } } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes *attribute = [super layoutAttributesForItemAtIndexPath:indexPath]; if (attribute.representedElementCategory == UICollectionElementCategoryCell) { if ([attribute.indexPath isEqual:_reorderingCellIndexPath]) { CGFloat alpha = 0; if ([self.delegate respondsToSelector:@selector(reorderingItemAlpha:)]) { alpha = [self.delegate reorderingItemAlpha:self.collectionView]; if (alpha >= 1.f) { alpha = 1.f; }else if (alpha <= 0) { alpha = 0; } } attribute.alpha = alpha; } } return attribute; } #pragma mark - Methods - (void)setUpCollectionViewGesture { if (!_setUped) { _longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; _longPressGesture.delegate = self; _panGesture.delegate = self; for (UIGestureRecognizer *gestureRecognizer in self.collectionView.gestureRecognizers) { if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) { [gestureRecognizer requireGestureRecognizerToFail:_longPressGesture]; }} [self.collectionView addGestureRecognizer:_longPressGesture]; [self.collectionView addGestureRecognizer:_panGesture]; _setUped = YES; } } - (void)setUpDisplayLink { if (_displayLink) { return; } _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(autoScroll)]; [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; } - (void)invalidateDisplayLink { [_displayLink invalidate]; _displayLink = nil; } - (void)autoScroll { CGPoint contentOffset = self.collectionView.contentOffset; UIEdgeInsets contentInset = self.collectionView.contentInset; CGSize contentSize = self.collectionView.contentSize; CGSize boundsSize = self.collectionView.bounds.size; CGFloat increment = 0; if (self.scrollDirection == RAScrollDirctionDown) { CGFloat percentage = (((CGRectGetMaxY(_cellFakeView.frame) - contentOffset.y) - (boundsSize.height - _scrollTrigerEdgeInsets.bottom - _scrollTrigePadding.bottom)) / _scrollTrigerEdgeInsets.bottom); increment = 10 * percentage; if (increment >= 10.f) { increment = 10.f; } }else if (self.scrollDirection == RAScrollDirctionUp) { CGFloat percentage = (1.f - ((CGRectGetMinY(_cellFakeView.frame) - contentOffset.y - _scrollTrigePadding.top) / _scrollTrigerEdgeInsets.top)); increment = -10.f * percentage; if (increment <= -10.f) { increment = -10.f; } } if (contentOffset.y + increment <= -contentInset.top) { [UIView animateWithDuration:.07f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ CGFloat diff = -contentInset.top - contentOffset.y; self.collectionView.contentOffset = CGPointMake(contentOffset.x, -contentInset.top); _cellFakeViewCenter = CGPointMake(_cellFakeViewCenter.x, _cellFakeViewCenter.y + diff); _cellFakeView.center = CGPointMake(_cellFakeViewCenter.x + _panTranslation.x, _cellFakeViewCenter.y + _panTranslation.y); } completion:nil]; [self invalidateDisplayLink]; return; }else if (contentOffset.y + increment >= contentSize.height - boundsSize.height - contentInset.bottom) { [UIView animateWithDuration:.07f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ CGFloat diff = contentSize.height - boundsSize.height - contentInset.bottom - contentOffset.y; self.collectionView.contentOffset = CGPointMake(contentOffset.x, contentSize.height - boundsSize.height - contentInset.bottom); _cellFakeViewCenter = CGPointMake(_cellFakeViewCenter.x, _cellFakeViewCenter.y + diff); _cellFakeView.center = CGPointMake(_cellFakeViewCenter.x + _panTranslation.x, _cellFakeViewCenter.y + _panTranslation.y); } completion:nil]; [self invalidateDisplayLink]; return; } [self.collectionView performBatchUpdates:^{ _cellFakeViewCenter = CGPointMake(_cellFakeViewCenter.x, _cellFakeViewCenter.y + increment); _cellFakeView.center = CGPointMake(_cellFakeViewCenter.x + _panTranslation.x, _cellFakeViewCenter.y + _panTranslation.y); self.collectionView.contentOffset = CGPointMake(contentOffset.x, contentOffset.y + increment); } completion:nil]; [self moveItemIfNeeded]; } - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)longPress { switch (longPress.state) { case UIGestureRecognizerStateBegan: { //indexPath NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:[longPress locationInView:self.collectionView]]; //can move if ([self.datasource respondsToSelector:@selector(collectionView:canMoveItemAtIndexPath:)]) { if (![self.datasource collectionView:self.collectionView canMoveItemAtIndexPath:indexPath]) { return; } } //will begin dragging if ([self.delegate respondsToSelector:@selector(collectionView:layout:willBeginDraggingItemAtIndexPath:)]) { [self.delegate collectionView:self.collectionView layout:self willBeginDraggingItemAtIndexPath:indexPath]; } //indexPath _reorderingCellIndexPath = indexPath; //scrolls top off self.collectionView.scrollsToTop = NO; //cell fake view UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; _cellFakeView = [[UIView alloc] initWithFrame:cell.frame]; _cellFakeView.layer.shadowColor = [UIColor blackColor].CGColor; _cellFakeView.layer.shadowOffset = CGSizeMake(0, 0); _cellFakeView.layer.shadowOpacity = .5f; _cellFakeView.layer.shadowRadius = 3.f; UIImageView *cellFakeImageView = [[UIImageView alloc] initWithFrame:cell.bounds]; UIImageView *highlightedImageView = [[UIImageView alloc] initWithFrame:cell.bounds]; cellFakeImageView.contentMode = UIViewContentModeScaleAspectFill; highlightedImageView.contentMode = UIViewContentModeScaleAspectFill; cellFakeImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; highlightedImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; cell.highlighted = YES; [highlightedImageView setCellCopiedImage:cell]; cell.highlighted = NO; [cellFakeImageView setCellCopiedImage:cell]; [self.collectionView addSubview:_cellFakeView]; [_cellFakeView addSubview:cellFakeImageView]; [_cellFakeView addSubview:highlightedImageView]; //set center _reorderingCellCenter = cell.center; _cellFakeViewCenter = _cellFakeView.center; [self invalidateLayout]; //animation CGRect fakeViewRect = CGRectMake(cell.center.x - (self.smallCellSize.width / 2.f), cell.center.y - (self.smallCellSize.height / 2.f), self.smallCellSize.width, self.smallCellSize.height); [UIView animateWithDuration:.3f delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{ _cellFakeView.center = cell.center; _cellFakeView.frame = fakeViewRect; _cellFakeView.transform = CGAffineTransformMakeScale(1.1f, 1.1f); highlightedImageView.alpha = 0; } completion:^(BOOL finished) { [highlightedImageView removeFromSuperview]; }]; //did begin dragging if ([self.delegate respondsToSelector:@selector(collectionView:layout:didBeginDraggingItemAtIndexPath:)]) { [self.delegate collectionView:self.collectionView layout:self didBeginDraggingItemAtIndexPath:indexPath]; } break; } case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: { NSIndexPath *currentCellIndexPath = _reorderingCellIndexPath; //will end dragging if ([self.delegate respondsToSelector:@selector(collectionView:layout:willEndDraggingItemAtIndexPath:)]) { [self.delegate collectionView:self.collectionView layout:self willEndDraggingItemAtIndexPath:currentCellIndexPath]; } //scrolls top on self.collectionView.scrollsToTop = YES; //disable auto scroll [self invalidateDisplayLink]; //remove fake view UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:currentCellIndexPath]; [UIView animateWithDuration:.3f delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{ _cellFakeView.transform = CGAffineTransformIdentity; _cellFakeView.frame = attributes.frame; } completion:^(BOOL finished) { [_cellFakeView removeFromSuperview]; _cellFakeView = nil; _reorderingCellIndexPath = nil; _reorderingCellCenter = CGPointZero; _cellFakeViewCenter = CGPointZero; [self invalidateLayout]; if (finished) { //did end dragging if ([self.delegate respondsToSelector:@selector(collectionView:layout:didEndDraggingItemAtIndexPath:)]) { [self.delegate collectionView:self.collectionView layout:self didEndDraggingItemAtIndexPath:currentCellIndexPath]; } } }]; break; } default: break; } } - (void)handlePanGesture:(UIPanGestureRecognizer *)pan { switch (pan.state) { case UIGestureRecognizerStateChanged: { //translation _panTranslation = [pan translationInView:self.collectionView]; _cellFakeView.center = CGPointMake(_cellFakeViewCenter.x + _panTranslation.x, _cellFakeViewCenter.y + _panTranslation.y); //move layout [self moveItemIfNeeded]; //scroll if (CGRectGetMaxY(_cellFakeView.frame) >= self.collectionView.contentOffset.y + (self.collectionView.bounds.size.height - _scrollTrigerEdgeInsets.bottom -_scrollTrigePadding.bottom)) { if (ceilf(self.collectionView.contentOffset.y) < self.collectionView.contentSize.height - self.collectionView.bounds.size.height) { self.scrollDirection = RAScrollDirctionDown; [self setUpDisplayLink]; } }else if (CGRectGetMinY(_cellFakeView.frame) <= self.collectionView.contentOffset.y + _scrollTrigerEdgeInsets.top + _scrollTrigePadding.top) { if (self.collectionView.contentOffset.y > -self.collectionView.contentInset.top) { self.scrollDirection = RAScrollDirctionUp; [self setUpDisplayLink]; } }else { self.scrollDirection = RAScrollDirctionNone; [self invalidateDisplayLink]; } break; } case UIGestureRecognizerStateCancelled: case UIGestureRecognizerStateEnded: [self invalidateDisplayLink]; break; default: break; } } - (void)moveItemIfNeeded { NSIndexPath *atIndexPath = _reorderingCellIndexPath; NSIndexPath *toIndexPath = [self.collectionView indexPathForItemAtPoint:_cellFakeView.center]; if (toIndexPath == nil || [atIndexPath isEqual:toIndexPath]) { return; } //can move if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:canMoveToIndexPath:)]) { if (![self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath canMoveToIndexPath:toIndexPath]) { return; } } //will move if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:willMoveToIndexPath:)]) { [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath willMoveToIndexPath:toIndexPath]; } //move [self.collectionView performBatchUpdates:^{ //update cell indexPath _reorderingCellIndexPath = toIndexPath; [self.collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath]; //did move if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) { [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath didMoveToIndexPath:toIndexPath]; } } completion:nil]; } #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if ([_panGesture isEqual:gestureRecognizer]) { if (_longPressGesture.state == 0 || _longPressGesture.state == 5) { return NO; } }else if ([_longPressGesture isEqual:gestureRecognizer]) { if (self.collectionView.panGestureRecognizer.state != 0 && self.collectionView.panGestureRecognizer.state != 5) { return NO; } } return YES; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if ([_panGesture isEqual:gestureRecognizer]) { if (_longPressGesture.state != 0 && _longPressGesture.state != 5) { if ([_longPressGesture isEqual:otherGestureRecognizer]) { return YES; } return NO; } }else if ([_longPressGesture isEqual:gestureRecognizer]) { if ([_panGesture isEqual:otherGestureRecognizer]) { return YES; } }else if ([self.collectionView.panGestureRecognizer isEqual:gestureRecognizer]) { if (_longPressGesture.state == 0 || _longPressGesture.state == 5) { return NO; } } return YES; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RACollectionViewReorderableTripletLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
3,510
```objective-c // // RAViewController.h // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/25/14. // #import <UIKit/UIKit.h> #import "RACollectionViewReorderableTripletLayout.h" @interface RAViewController : UIViewController <RACollectionViewDelegateReorderableTripletLayout, RACollectionViewReorderableTripletLayoutDataSource> @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RAViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
91
```objective-c // // RACollectionViewTripletLayout.h // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/25/14. // #import <UIKit/UIKit.h> #define RACollectionViewTripletLayoutStyleSquare CGSizeZero @protocol RACollectionViewDelegateTripletLayout <UICollectionViewDelegateFlowLayout> @optional - (CGSize)collectionView:(UICollectionView *)collectionView sizeForLargeItemsInSection:(NSInteger)section; //Default to automaticaly grow square ! - (UIEdgeInsets)insetsForCollectionView:(UICollectionView *)collectionView; - (CGFloat)sectionSpacingForCollectionView:(UICollectionView *)collectionView; - (CGFloat)minimumInteritemSpacingForCollectionView:(UICollectionView *)collectionView; - (CGFloat)minimumLineSpacingForCollectionView:(UICollectionView *)collectionView; @end @protocol RACollectionViewTripletLayoutDatasource <UICollectionViewDataSource> @end @interface RACollectionViewTripletLayout : UICollectionViewFlowLayout @property (nonatomic, weak) id<RACollectionViewDelegateTripletLayout> delegate; @property (nonatomic, weak) id<RACollectionViewTripletLayoutDatasource> datasource; @property (nonatomic, assign, readonly) CGSize largeCellSize; @property (nonatomic, assign, readonly) CGSize smallCellSize; - (CGFloat)contentHeight; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RACollectionViewTripletLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
263
```objective-c // // RACollectionViewTripletLayout.m // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/25/14. // #import "RACollectionViewTripletLayout.h" @interface RACollectionViewTripletLayout() @property (nonatomic, assign) NSInteger numberOfCells; @property (nonatomic, assign) CGFloat numberOfLines; @property (nonatomic, assign) CGFloat itemSpacing; @property (nonatomic, assign) CGFloat lineSpacing; @property (nonatomic, assign) CGFloat sectionSpacing; @property (nonatomic, assign) CGSize collectionViewSize; @property (nonatomic, assign) UIEdgeInsets insets; @property (nonatomic, assign) CGRect oldRect; @property (nonatomic, strong) NSArray *oldArray; @property (nonatomic, strong) NSMutableArray *largeCellSizeArray; @property (nonatomic, strong) NSMutableArray *smallCellSizeArray; @end @implementation RACollectionViewTripletLayout #pragma mark - Over ride flow layout methods - (void)prepareLayout { [super prepareLayout]; //collection view size _collectionViewSize = self.collectionView.bounds.size; //some values _itemSpacing = 0; _lineSpacing = 0; _sectionSpacing = 0; _insets = UIEdgeInsetsMake(0, 0, 0, 0); if ([self.delegate respondsToSelector:@selector(minimumInteritemSpacingForCollectionView:)]) { _itemSpacing = [self.delegate minimumInteritemSpacingForCollectionView:self.collectionView]; } if ([self.delegate respondsToSelector:@selector(minimumLineSpacingForCollectionView:)]) { _lineSpacing = [self.delegate minimumLineSpacingForCollectionView:self.collectionView]; } if ([self.delegate respondsToSelector:@selector(sectionSpacingForCollectionView:)]) { _sectionSpacing = [self.delegate sectionSpacingForCollectionView:self.collectionView]; } if ([self.delegate respondsToSelector:@selector(insetsForCollectionView:)]) { _insets = [self.delegate insetsForCollectionView:self.collectionView]; } } - (CGFloat)contentHeight { CGFloat contentHeight = 0; NSInteger numberOfSections = self.collectionView.numberOfSections; CGSize collectionViewSize = self.collectionView.bounds.size; UIEdgeInsets insets = UIEdgeInsetsZero; if ([self.delegate respondsToSelector:@selector(insetsForCollectionView:)]) { insets = [self.delegate insetsForCollectionView:self.collectionView]; } CGFloat sectionSpacing = 0; if ([self.delegate respondsToSelector:@selector(sectionSpacingForCollectionView:)]) { sectionSpacing = [self.delegate sectionSpacingForCollectionView:self.collectionView]; } CGFloat itemSpacing = 0; if ([self.delegate respondsToSelector:@selector(minimumInteritemSpacingForCollectionView:)]) { itemSpacing = [self.delegate minimumInteritemSpacingForCollectionView:self.collectionView]; } CGFloat lineSpacing = 0; if ([self.delegate respondsToSelector:@selector(minimumLineSpacingForCollectionView:)]) { lineSpacing = [self.delegate minimumLineSpacingForCollectionView:self.collectionView]; } contentHeight += insets.top + insets.bottom + sectionSpacing * (numberOfSections - 1); CGFloat lastSmallCellHeight = 0; for (NSInteger i = 0; i < numberOfSections; i++) { NSInteger numberOfLines = ceil((CGFloat)[self.collectionView numberOfItemsInSection:i] / 3.f); CGFloat largeCellSideLength = (2.f * (collectionViewSize.width - insets.left - insets.right) - itemSpacing) / 3.f; CGFloat smallCellSideLength = (largeCellSideLength - itemSpacing) / 2.f; CGSize largeCellSize = CGSizeMake(largeCellSideLength, largeCellSideLength); CGSize smallCellSize = CGSizeMake(smallCellSideLength, smallCellSideLength); if ([self.delegate respondsToSelector:@selector(collectionView:sizeForLargeItemsInSection:)]) { if (!CGSizeEqualToSize([self.delegate collectionView:self.collectionView sizeForLargeItemsInSection:i], RACollectionViewTripletLayoutStyleSquare)) { largeCellSize = [self.delegate collectionView:self.collectionView sizeForLargeItemsInSection:i]; smallCellSize = CGSizeMake(collectionViewSize.width - largeCellSize.width - itemSpacing - insets.left - insets.right, (largeCellSize.height / 2.f) - (itemSpacing / 2.f)); } } lastSmallCellHeight = smallCellSize.height; CGFloat largeCellHeight = largeCellSize.height; CGFloat lineHeight = numberOfLines * (largeCellHeight + lineSpacing) - lineSpacing; contentHeight += lineHeight; } NSInteger numberOfItemsInLastSection = [self.collectionView numberOfItemsInSection:numberOfSections -1]; if ((numberOfItemsInLastSection - 1) % 3 == 0 && (numberOfItemsInLastSection - 1) % 6 != 0) { contentHeight -= lastSmallCellHeight + itemSpacing; } return contentHeight; } - (void)setDelegate:(id<RACollectionViewDelegateTripletLayout>)delegate { self.collectionView.delegate = delegate; } - (id<RACollectionViewDelegateTripletLayout>)delegate { return (id<RACollectionViewDelegateTripletLayout>)self.collectionView.delegate; } - (CGSize)collectionViewContentSize { CGSize contentSize = CGSizeMake(_collectionViewSize.width, 0); for (NSInteger i = 0; i < self.collectionView.numberOfSections; i++) { if ([self.collectionView numberOfItemsInSection:i] == 0) { break; } NSInteger numberOfLines = ceil((CGFloat)[self.collectionView numberOfItemsInSection:i] / 3.f); CGFloat lineHeight = numberOfLines * ([_largeCellSizeArray[i] CGSizeValue].height + _lineSpacing) - _lineSpacing; contentSize.height += lineHeight; } contentSize.height += _insets.top + _insets.bottom + _sectionSpacing * (self.collectionView.numberOfSections - 1); NSInteger numberOfItemsInLastSection = [self.collectionView numberOfItemsInSection:self.collectionView.numberOfSections - 1]; if ((numberOfItemsInLastSection - 1) % 3 == 0 && (numberOfItemsInLastSection - 1) % 6 != 0) { contentSize.height -= [_smallCellSizeArray[self.collectionView.numberOfSections - 1] CGSizeValue].height + _itemSpacing; } return contentSize; } - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { _oldRect = rect; NSMutableArray *attributesArray = [NSMutableArray array]; for (NSInteger i = 0; i < self.collectionView.numberOfSections; i++) { NSInteger numberOfCellsInSection = [self.collectionView numberOfItemsInSection:i]; for (NSInteger j = 0; j < numberOfCellsInSection; j++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:j inSection:i]; UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath]; if (CGRectIntersectsRect(rect, attributes.frame)) { [attributesArray addObject:attributes]; } } } _oldArray = attributesArray; return attributesArray; } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes *attribute = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; //cellSize CGFloat largeCellSideLength = (2.f * (_collectionViewSize.width - _insets.left - _insets.right) - _itemSpacing) / 3.f; CGFloat smallCellSideLength = (largeCellSideLength - _itemSpacing) / 2.f; _largeCellSize = CGSizeMake(largeCellSideLength, largeCellSideLength); _smallCellSize = CGSizeMake(smallCellSideLength, smallCellSideLength); if ([self.delegate respondsToSelector:@selector(collectionView:sizeForLargeItemsInSection:)]) { if (!CGSizeEqualToSize([self.delegate collectionView:self.collectionView sizeForLargeItemsInSection:indexPath.section], RACollectionViewTripletLayoutStyleSquare)) { _largeCellSize = [self.delegate collectionView:self.collectionView sizeForLargeItemsInSection:indexPath.section]; _smallCellSize = CGSizeMake(_collectionViewSize.width - _largeCellSize.width - _itemSpacing - _insets.left - _insets.right, (_largeCellSize.height / 2.f) - (_itemSpacing / 2.f)); } } if (!_largeCellSizeArray) { _largeCellSizeArray = [NSMutableArray array]; } if (!_smallCellSizeArray) { _smallCellSizeArray = [NSMutableArray array]; } _largeCellSizeArray[indexPath.section] = [NSValue valueWithCGSize:_largeCellSize]; _smallCellSizeArray[indexPath.section] = [NSValue valueWithCGSize:_smallCellSize]; //section height CGFloat sectionHeight = 0; for (NSInteger i = 0; i <= indexPath.section - 1; i++) { NSInteger cellsCount = [self.collectionView numberOfItemsInSection:i]; CGFloat largeCellHeight = [_largeCellSizeArray[i] CGSizeValue].height; CGFloat smallCellHeight = [_smallCellSizeArray[i] CGSizeValue].height; NSInteger lines = ceil((CGFloat)cellsCount / 3.f); sectionHeight += lines * (_lineSpacing + largeCellHeight) + _sectionSpacing; if ((cellsCount - 1) % 3 == 0 && (cellsCount - 1) % 6 != 0) { sectionHeight -= smallCellHeight + _itemSpacing; } } if (sectionHeight > 0) { sectionHeight -= _lineSpacing; } NSInteger line = indexPath.item / 3; CGFloat lineSpaceForIndexPath = _lineSpacing * line; CGFloat lineOriginY = _largeCellSize.height * line + sectionHeight + lineSpaceForIndexPath + _insets.top; CGFloat rightSideLargeCellOriginX = _collectionViewSize.width - _largeCellSize.width - _insets.right; CGFloat rightSideSmallCellOriginX = _collectionViewSize.width - _smallCellSize.width - _insets.right; if (indexPath.item % 6 == 0) { attribute.frame = CGRectMake(_insets.left, lineOriginY, _largeCellSize.width, _largeCellSize.height); }else if ((indexPath.item + 1) % 6 == 0) { attribute.frame = CGRectMake(rightSideLargeCellOriginX, lineOriginY, _largeCellSize.width, _largeCellSize.height); }else if (line % 2 == 0) { if (indexPath.item % 2 != 0) { attribute.frame = CGRectMake(rightSideSmallCellOriginX, lineOriginY, _smallCellSize.width, _smallCellSize.height); }else { attribute.frame =CGRectMake(rightSideSmallCellOriginX, lineOriginY + _smallCellSize.height + _itemSpacing, _smallCellSize.width, _smallCellSize.height); } }else { if (indexPath.item % 2 != 0) { attribute.frame = CGRectMake(_insets.left, lineOriginY, _smallCellSize.width, _smallCellSize.height); }else { attribute.frame =CGRectMake(_insets.left, lineOriginY + _smallCellSize.height + _itemSpacing, _smallCellSize.width, _smallCellSize.height); } } return attribute; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RACollectionViewTripletLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,373
```objective-c // // YFScrollViewController.m // BigShow1949 // // Created by zhht01 on 16/1/14. // #import "YFScrollViewController.h" @interface YFScrollViewController () @end @implementation YFScrollViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"",@"YFBlurtViewController"], @[@"UITableView",@"YFTableViewDelAll"], @[@"UITableViewCell",@"RootViewController_xib"],]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFScrollViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
107
```objective-c // // YFScrollViewController.h // BigShow1949 // // Created by zhht01 on 16/1/14. // #import "BaseTableViewController.h" @interface YFScrollViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFScrollViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
53
```objective-c // // YFBlurtViewController.h // BigShow1949 // // Created by zhht01 on 16/1/14. // #import <UIKit/UIKit.h> @interface YFBlurtViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // RACollectionViewCell.m // RACollectionViewTripletLayout-Demo // // Created by Ryo Aoyama on 5/27/14. // #import "RACollectionViewCell.h" @implementation RACollectionViewCell - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { _imageView = [[UIImageView alloc] init]; _imageView.contentMode = UIViewContentModeScaleAspectFill; } return self; } - (void)setBounds:(CGRect)bounds { [super setBounds:bounds]; self.imageView.frame = bounds; } - (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; if (highlighted) { _imageView.alpha = .7f; }else { _imageView.alpha = 1.f; } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UICollectionView/RACollectionViewController/RACollectionViewCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
197
```objective-c // // YFBlurtView.h // BigShow1949 // // Created by zhht01 on 16/1/14. // #import <UIKit/UIKit.h> typedef void (^SelectRowAction)(NSIndexPath *); @interface YFBlurtView : UIView { SelectRowAction selectAction; } @property (nonatomic,assign)CGFloat headerImgHeight; @property (nonatomic,assign)CGFloat iconHeight; /** * url */ @property (nonatomic,copy)NSString *imgUrl; @property (nonatomic,copy)NSString *name; - (instancetype)initWithFrame:(CGRect)frame WithHeaderImgHeight:(CGFloat)headerImgHeight iconHeight:(CGFloat)iconHeight selectBlock:(SelectRowAction)block; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
145
```objective-c // // YFBlurtViewController.m // BigShow1949 // // Created by zhht01 on 16/1/14. // #import "YFBlurtViewController.h" #import "YFBlurtView.h" @interface YFBlurtViewController () @end @implementation YFBlurtViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; YFBlurtView *b = [[YFBlurtView alloc] initWithFrame:self.view.frame WithHeaderImgHeight:170 iconHeight:100 selectBlock:^(NSIndexPath *indexPath) { NSLog(@"indexpath.row is %zi indexpath.section is %zi",indexPath.row,indexPath.section); }]; [self.view addSubview:b]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
247
```objective-c // // UIImageView+YFBlurtImage.h // BigShow1949 // // Created by zhht01 on 16/1/14. // #import <UIKit/UIKit.h> typedef void(^YFBlurredImageCompletionBlock)(void); extern CGFloat const kYFBlurredImageDefaultBlurRadius; @interface UIImageView (YFBlurtImage) /** Set the blurred version of the provided image to the UIImageView @param UIImage the image to blur and set as UIImageView's image @param CGFLoat the radius of the blur used by the Gaussian filter @param LBBlurredImageCompletionBlock a completion block called after the image was blurred and set to the UIImageView (the block is dispatched on main thread) */ - (void)setImageToBlur:(UIImage *)image blurRadius:(CGFloat)blurRadius completionBlock:(YFBlurredImageCompletionBlock)completion; /** Set the blurred version of the provided image to the UIImageView with the default blur radius @param UIImage the image to blur and set as UIImageView's image @param LBBlurredImageCompletionBlock a completion block called after the image was blurred and set to the UIImageView (the block is dispatched on main thread) */ - (void)setImageToBlur:(UIImage *)image completionBlock:(YFBlurredImageCompletionBlock)completion; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtImage/UIImageView+YFBlurtImage.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
284
```objective-c // // UIImageView+YFBlurtImage.m // BigShow1949 // // Created by zhht01 on 16/1/14. // #import "UIImageView+YFBlurtImage.h" #import "UIImage+ImageEffects.h" CGFloat const kYFBlurredImageDefaultBlurRadius = 20.0; CGFloat const kYFBlurredImageDefaultSaturationDeltaFactor = 1.8; @implementation UIImageView (YFBlurtImage) #pragma mark - LBBlurredImage Additions - (void)setImageToBlur:(UIImage *)image completionBlock:(YFBlurredImageCompletionBlock)completion { [self setImageToBlur:image blurRadius:kYFBlurredImageDefaultBlurRadius completionBlock:completion]; } - (void)setImageToBlur:(UIImage *)image blurRadius:(CGFloat)blurRadius completionBlock:(YFBlurredImageCompletionBlock) completion { NSParameterAssert(image); NSParameterAssert(blurRadius >= 0); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIImage *blurredImage = [image applyBlurWithRadius:blurRadius tintColor:nil saturationDeltaFactor:kYFBlurredImageDefaultSaturationDeltaFactor maskImage:nil]; dispatch_async(dispatch_get_main_queue(), ^{ self.image = blurredImage; if (completion) { completion(); } }); }); } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtImage/UIImageView+YFBlurtImage.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
317
```objective-c // // YFBlurtView.m // BigShow1949 // // Created by zhht01 on 16/1/14. // #import "YFBlurtView.h" #import "UIImageView+WebCache.h" #import "UIImageView+YFBlurtImage.h" #define changeRate (self.frame.size.width / self.frame.size.height) @interface YFBlurtView ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate> /** * */ @property (nonatomic,strong)UIImageView *imageView; @property (nonatomic,strong)UIImageView *headImage; @property (nonatomic,strong)UITableView *mTableView; /** * view */ @property (nonatomic,strong)UIView *otherView; /** * */ @property (nonatomic,assign)CGFloat scale; /** * label */ @property (nonatomic,strong)UILabel *label; @end @implementation YFBlurtView - (instancetype)initWithFrame:(CGRect)frame WithHeaderImgHeight:(CGFloat)headerImgHeight iconHeight:(CGFloat)iconHeight selectBlock:(SelectRowAction)block { if (self = [super initWithFrame:frame]) { self.headerImgHeight = (headerImgHeight == 0 ? self.frame.size.height * 0.382 : headerImgHeight); self.iconHeight = (iconHeight == 0 ? self.frame.size.height * 0.382 : iconHeight); [self setupContentView]; selectAction = block; } return self; } - (void)setupContentView { NSAssert(self.headerImgHeight >= self.iconHeight && self.iconHeight > 0, @""); // imageView UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.headerImgHeight)]; imageView.contentMode = UIViewContentModeScaleAspectFill; self.imageView = imageView; self.scale = self.imageView.frame.size.width / self.imageView.frame.size.height; UIImage *image = [UIImage imageNamed:@"blurtView1.jpg"]; imageView.image = image; // 20 R [imageView setImageToBlur:imageView.image blurRadius:20 completionBlock:nil]; // headImage UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake((self.frame.size.width - self.iconHeight) / 2, (self.headerImgHeight - self.iconHeight) / 2, self.iconHeight, self.iconHeight)]; icon.backgroundColor = [UIColor yellowColor]; icon.image = [UIImage imageNamed:@"blurtView1.jpg"]; icon.layer.cornerRadius = self.iconHeight * 0.5; icon.clipsToBounds = YES; self.headImage = icon; // // [self.headImage sd_setImageWithURL:[NSURL URLWithString:self.imgUrl] placeholderImage:[UIImage imageNamed:@"blurtView1.jpg"]]; // // [imageView sd_setImageWithURL:[NSURL URLWithString:self.imgUrl] placeholderImage:[UIImage imageNamed:@"blurtView1.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { // // 20 R // [imageView setImageToBlur:imageView.image blurRadius:21 completionBlock:nil]; // }]; // otherView UIView *otherVIew = [[UIView alloc] initWithFrame:CGRectMake(0, self.headerImgHeight, self.frame.size.width,self.imageView.frame.size.height)]; otherVIew.backgroundColor = [UIColor clearColor]; self.otherView = otherVIew; [self.otherView addSubview:self.headImage]; // label UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(icon.frame) + 10, self.frame.size.width, 20)]; self.label = name; name.text = (self.name ? self.name : @"Charles"); name.textAlignment = NSTextAlignmentCenter; name.textColor = [UIColor whiteColor]; [self.otherView addSubview:self.label]; // mTableView self.mTableView.tableHeaderView = imageView; [self addSubview:imageView]; self.mTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,64, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain]; NSLog(@"%@",NSStringFromCGRect(self.frame)); self.mTableView.backgroundColor = [UIColor clearColor]; self.mTableView.delegate = self; self.mTableView.dataSource = self; self.mTableView.decelerationRate = 2; [self addSubview:self.mTableView]; self.mTableView.tableHeaderView = self.otherView; } #pragma mark -UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 60; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * strID = @"ID"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:strID]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strID]; } cell.textLabel.text = [NSString stringWithFormat:@"%zi",indexPath.row+1]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ selectAction(indexPath); } #pragma mark - UIScrollViewDelgate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = scrollView.contentOffset.y; if (scrollView.contentOffset.y < 0) { // CGFloat imgH = self.headerImgHeight - scrollView.contentOffset.y * 2; CGFloat imgW = imgH * self.scale; self.imageView.frame = CGRectMake(scrollView.contentOffset.y * self.scale,0, imgW,imgH); CGFloat iconOriginalX = (self.frame.size.width - self.iconHeight) / 2; CGFloat iconOriginalY = (self.headerImgHeight - self.iconHeight) / 2; self.headImage.frame = CGRectMake(iconOriginalX + offsetY * changeRate, iconOriginalY + offsetY * changeRate * 2, self.iconHeight - changeRate * offsetY * 2, self.iconHeight - changeRate * offsetY * 2); self.headImage.layer.cornerRadius = self.headImage.frame.size.width * 0.5; self.headImage.clipsToBounds = YES; self.label.frame = CGRectMake(self.label.frame.origin.x, CGRectGetMaxY(self.headImage.frame) + 10, self.label.frame.size.width, self.label.frame.size.height); } else { // self.imageView.frame = CGRectMake(0, 0, self.imageView.frame.size.width, 200 - scrollView.contentOffset.y); } NSLog(@"%0.0f",scrollView.contentOffset.y); } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,370
```objective-c /* File: UIImage+ImageEffects.h Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code youll want to look out to find out how to use vImage to efficiently calculate a blur. Version: 1.0 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 Session. Please refer to the applicable WWDC 2013 Session for further information. IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EA1002 5/3/2013 */ #import <UIKit/UIKit.h> @interface UIImage (ImageEffects) - (UIImage *)applyLightEffect; - (UIImage *)applyExtraLightEffect; - (UIImage *)applyDarkEffect; - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor; - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtImage/UIImage+ImageEffects.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,128
```objective-c // // SecondViewController.m // MutableMenuTableView // // Created by on 16/4/28. // #import "SecondViewController.h" #import "SecondMenuData.h" @interface SecondViewController () @property (nonatomic,strong)SecondMenuData *secondData; @end @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.title=self.item.title; self.secondData=[[SecondMenuData alloc]init]; oldindex=-1; } #pragma mark - Table view data source - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ MyItem *item=[self.secondData.tableViewData objectAtIndex:section]; UIView *headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)]; headview.backgroundColor=[UIColor whiteColor]; UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; [btn setFrame:CGRectMake(0, 1, self.view.frame.size.width, 43)]; btn.tag=1000+section; [btn setBackgroundColor:[UIColor grayColor]]; [btn addTarget:self action:@selector(headViewClicked:) forControlEvents:UIControlEventTouchUpInside]; [btn setTitle:item.title forState:UIControlStateNormal]; [headview addSubview:btn]; return headview; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 45; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.1; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return [self.secondData.tableViewData count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { MyItem *item=[self.secondData.tableViewData objectAtIndex:section]; return flag[section]?[item.subItems count]:0; // Return the number of rows in the section. //return [[MenuData sharedMenuData].tableViewData count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"cell"; UITableViewCell * itemCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (itemCell == nil) { itemCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];; } if([self.secondData.tableViewData count]) { MyItem *item=[self.secondData.tableViewData objectAtIndex:indexPath.section]; if([item.subItems count]) { MyItem *item1=[item.subItems objectAtIndex:indexPath.row]; itemCell.textLabel.text=item1.title; } } return itemCell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } -(void)headViewClicked:(id)sender { UIButton *headBtn=(UIButton *)sender; if(oldindex!=headBtn.tag-1000) { flag[oldindex]=NO; } flag[headBtn.tag-1000]=!flag[headBtn.tag-1000]; [self.secondTableView reloadData]; oldindex =headBtn.tag-1000; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/SecondViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
759
```objective-c // // SecondViewController.h // MutableMenuTableView // // Created by on 16/4/28. // #import <UIKit/UIKit.h> #import "MyItem.h" @interface SecondViewController : UIViewController { BOOL flag[100]; NSInteger oldindex; } @property (weak, nonatomic) IBOutlet UITableView *secondTableView; @property (nonatomic,strong)MyItem *item; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/SecondViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
84
```objective-c /* File: UIImage+ImageEffects.m Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code youll want to look out to find out how to use vImage to efficiently calculate a blur. Version: 1.0 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 Session. Please refer to the applicable WWDC 2013 Session for further information. IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EA1002 5/3/2013 */ #import "UIImage+ImageEffects.h" #import <Accelerate/Accelerate.h> #import <float.h> @implementation UIImage (ImageEffects) - (UIImage *)applyLightEffect { UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3]; return [self applyBlurWithRadius:30 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; } - (UIImage *)applyExtraLightEffect { UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82]; return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; } - (UIImage *)applyDarkEffect { UIColor *tintColor = [UIColor colorWithWhite:0.11 alpha:0.73]; return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; } - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor { const CGFloat EffectColorAlpha = 0.6; UIColor *effectColor = tintColor; int componentCount = CGColorGetNumberOfComponents(tintColor.CGColor); if (componentCount == 2) { CGFloat b; if ([tintColor getWhite:&b alpha:NULL]) { effectColor = [UIColor colorWithWhite:b alpha:EffectColorAlpha]; } } else { CGFloat r, g, b; if ([tintColor getRed:&r green:&g blue:&b alpha:NULL]) { effectColor = [UIColor colorWithRed:r green:g blue:b alpha:EffectColorAlpha]; } } return [self applyBlurWithRadius:10 tintColor:effectColor saturationDeltaFactor:-1.0 maskImage:nil]; } - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage { // Check pre-conditions. if (self.size.width < 1 || self.size.height < 1) { NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", self.size.width, self.size.height, self); return nil; } if (!self.CGImage) { NSLog (@"*** error: image must be backed by a CGImage: %@", self); return nil; } if (maskImage && !maskImage.CGImage) { NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage); return nil; } CGRect imageRect = { CGPointZero, self.size }; UIImage *effectImage = self; BOOL hasBlur = blurRadius > __FLT_EPSILON__; BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__; if (hasBlur || hasSaturationChange) { UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]); CGContextRef effectInContext = UIGraphicsGetCurrentContext(); CGContextScaleCTM(effectInContext, 1.0, -1.0); CGContextTranslateCTM(effectInContext, 0, -self.size.height); CGContextDrawImage(effectInContext, imageRect, self.CGImage); vImage_Buffer effectInBuffer; effectInBuffer.data = CGBitmapContextGetData(effectInContext); effectInBuffer.width = CGBitmapContextGetWidth(effectInContext); effectInBuffer.height = CGBitmapContextGetHeight(effectInContext); effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext); UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]); CGContextRef effectOutContext = UIGraphicsGetCurrentContext(); vImage_Buffer effectOutBuffer; effectOutBuffer.data = CGBitmapContextGetData(effectOutContext); effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext); effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext); effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext); if (hasBlur) { // A description of how to compute the box kernel width from the Gaussian // radius (aka standard deviation) appears in the SVG spec: // path_to_url#feGaussianBlurElement // // For larger values of 's' (s >= 2.0), an approximation can be used: Three // successive box-blurs build a piece-wise quadratic convolution kernel, which // approximates the Gaussian kernel to within roughly 3%. // // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5) // // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel. // CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale]; NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5); if (radius % 2 != 1) { radius += 1; // force radius to be odd so that the three box-blur methodology works. } vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend); vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend); vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend); } BOOL effectImageBuffersAreSwapped = NO; if (hasSaturationChange) { CGFloat s = saturationDeltaFactor; CGFloat floatingPointSaturationMatrix[] = { 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0, 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0, 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0, 0, 0, 0, 1, }; const int32_t divisor = 256; NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]); int16_t saturationMatrix[matrixSize]; for (NSUInteger i = 0; i < matrixSize; ++i) { saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor); } if (hasBlur) { vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags); effectImageBuffersAreSwapped = YES; } else { vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags); } } if (!effectImageBuffersAreSwapped) effectImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (effectImageBuffersAreSwapped) effectImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } // Set up output context. UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]); CGContextRef outputContext = UIGraphicsGetCurrentContext(); CGContextScaleCTM(outputContext, 1.0, -1.0); CGContextTranslateCTM(outputContext, 0, -self.size.height); // Draw base image. CGContextDrawImage(outputContext, imageRect, self.CGImage); // Draw effect image. if (hasBlur) { CGContextSaveGState(outputContext); if (maskImage) { CGContextClipToMask(outputContext, imageRect, maskImage.CGImage); } CGContextDrawImage(outputContext, imageRect, effectImage.CGImage); CGContextRestoreGState(outputContext); } // Add in color tint. if (tintColor) { CGContextSaveGState(outputContext); CGContextSetFillColorWithColor(outputContext, tintColor.CGColor); CGContextFillRect(outputContext, imageRect); CGContextRestoreGState(outputContext); } // Output image is ready. UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return outputImage; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/YFBlurtView/YFBlurtImage/UIImage+ImageEffects.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,962
```objective-c // // RootViewController.h // MutableMenuTableView // // Created by on 16/4/27. // #import <UIKit/UIKit.h> #import "MenuData.h" #import "MenuItemCell.h" #import "SecondViewController.h" @interface RootViewController : UIViewController @property (nonatomic,strong)NSIndexPath *myIndexPath; @property (nonatomic,strong)MenuData *menuData; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/RootViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
82
```objective-c // // RootViewController.m // MutableMenuTableView // // Created by on 16/4/27. // #import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.menuData = [[MenuData alloc] init]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.menuData = [[MenuData alloc] init]; self.myIndexPath=nil; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [_menuData.tableViewData count]; //return [[MenuData sharedMenuData].tableViewData count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat: @"Cell%ld",(long)indexPath.row]; MenuItemCell * itemCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (itemCell == nil) { itemCell = [[[NSBundle mainBundle] loadNibNamed:@"MenuItemCell" owner:nil options:nil]lastObject]; } MyItem *item; item = [_menuData.tableViewData objectAtIndex:indexPath.row]; itemCell.item = item; [itemCell setLevel:item.level]; return itemCell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MenuItemCell * cell; cell = (MenuItemCell *)[tableView cellForRowAtIndexPath:indexPath]; if (cell.item.isSubItemOpen) { //remove NSArray * arr; arr = [_menuData cascadingDeletePaths:indexPath]; if ([arr count] >0) { [tableView deleteRowsAtIndexPaths: arr withRowAnimation:UITableViewRowAnimationBottom]; self.myIndexPath=indexPath; } else { MyItem *item; item = [_menuData.tableViewData objectAtIndex:indexPath.row]; SecondViewController *second=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; second.item=item; [self.navigationController pushViewController:second animated:YES]; } } else { //insert NSArray * arr; arr = [_menuData cascadingInsertCellPaths:indexPath]; if ([arr count] >0) { [tableView insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationBottom]; self.myIndexPath=indexPath; } else { MyItem *item; item = [_menuData.tableViewData objectAtIndex:indexPath.row]; SecondViewController *second=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; second.item=item; [self.navigationController pushViewController:second animated:YES]; } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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 ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/RootViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
744
```objective-c // // MenuData.h // MutableMenuTableView // // Created by on 16/4/27. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "MyItem.h" @interface MenuData : NSObject { NSMutableArray * treeItemsToRemove; NSMutableArray * treeItemsToInsert; } @property (nonatomic,strong) NSMutableArray *tableViewData; @property (nonatomic,strong) NSMutableArray *treeItemsToRemove; @property (nonatomic,strong) NSMutableArray *treeItemsToInsert; - (NSMutableArray *) cascadingDeletePaths:(NSIndexPath *)indexPath; - (NSMutableArray *) cascadingInsertCellPaths:(NSIndexPath *)indexPath; - (NSMutableArray *) deleteCellPaths: (NSIndexPath *)indexPath; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/MenuData.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
145
```objective-c // // SecondMenuData.m // MutableMenuTableView // // Created by on 16/4/28. // #import "SecondMenuData.h" @implementation SecondMenuData -(id)init { self=[super init]; if(self) { self.tableViewData=[NSMutableArray array]; [self getData]; } return self; } -(void)getData { // NSMutableArray *arr0=[NSMutableArray array]; NSMutableArray *arr1=[NSMutableArray array]; NSMutableArray *arr2=[NSMutableArray array]; for(int i=0 ; i<10 ; i++) { MyItem *item=[[MyItem alloc] init]; item.classId_=@"0"; item.id_=[NSString stringWithFormat:@"%d",i]; item.title=[NSString stringWithFormat:@"title_%d",i]; [arr0 addObject:item]; for(int j=0;j<3;j++) { MyItem *item=[[MyItem alloc] init]; item.classId_=[NSString stringWithFormat:@"%d",i]; item.id_=[NSString stringWithFormat:@"%d",10+i*3+j+1]; item.title=[NSString stringWithFormat:@"title_%d",10+i*3+j+1]; [arr1 addObject:item]; } } NSLog(@"%@",arr2); // for(int i=0 ;i<[arr0 count];i++) { MyItem *item0=[arr0 objectAtIndex:i]; item0.level=0; item0.subItems=[NSMutableArray array]; for(int j=0;j<[arr1 count];j++) { MyItem *item1=[arr1 objectAtIndex:j]; if([item1.classId_ isEqualToString:item0.id_]) { item1.level=1; item1.subItems=[NSMutableArray array]; [item0.subItems addObject:item1]; } } [_tableViewData addObject:item0]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/SecondMenuData.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
411
```objective-c // // SecondMenuData.h // MutableMenuTableView // // Created by on 16/4/28. // #import <Foundation/Foundation.h> #import "MyItem.h" @interface SecondMenuData : NSObject @property (nonatomic,strong) MyItem *item; @property (nonatomic,strong) NSMutableArray *tableViewData; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/SecondMenuData.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
71
```objective-c // // MenuItemCell.h // MutableMenuTableView // // Created by on 16/4/27. // #import <UIKit/UIKit.h> #import "MyItem.h" @interface MenuItemCell : UITableViewCell @property (weak, nonatomic) IBOutlet UILabel *label; @property (weak, nonatomic) IBOutlet UILabel *detailLabel; @property (nonatomic,strong) MyItem *item; -(void)setLevel:(NSInteger)level; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/MenuItemCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
91
```objective-c // // MenuItemCell.m // MutableMenuTableView // // Created by on 16/4/27. // #import "MenuItemCell.h" @implementation MenuItemCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(void)setLevel:(NSInteger)level { if(self.item) { self.label.text=self.item.title; if([self.item.subItems count]>0) { self.detailLabel.text=[NSString stringWithFormat:@"%lu",(unsigned long)[self.item.subItems count]]; self.detailLabel.textColor=[UIColor blueColor]; } else { self.detailLabel.text=@"-"; self.detailLabel.textColor=[UIColor grayColor]; } } CGRect labelRec=self.label.frame; labelRec.origin.x=20*level+10; self.label.frame=labelRec; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/MenuItemCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
217
```objective-c // // MyItem.h // MutableMenuTableView // // Created by on 16/4/27. // #import <Foundation/Foundation.h> @interface MyItem : NSObject @property (nonatomic,strong) NSString *id_; @property (nonatomic,strong) NSString *classId_; @property (nonatomic,strong) NSString *title; @property (nonatomic,assign) NSInteger level; @property (nonatomic,strong) NSMutableArray *subItems; @property (nonatomic,assign) BOOL isSubItemOpen; @property (nonatomic,assign)BOOL isCascadeOpen; @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/MyItem.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
110
```objective-c // // MyItem.m // MutableMenuTableView // // Created by on 16/4/27. // #import "MyItem.h" @implementation MyItem -(id)init { self=[super init]; return self; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/MyItem.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
58
```objective-c // // MenuData.m // MutableMenuTableView // // Created by on 16/4/27. // #import "MenuData.h" @implementation MenuData @synthesize treeItemsToInsert; @synthesize treeItemsToRemove; -(id)init { self=[super init]; if(self) { self.tableViewData = [NSMutableArray array]; self.treeItemsToInsert=[NSMutableArray array]; self.treeItemsToRemove=[NSMutableArray array]; [self getData]; } return self; } -(void)getData { // NSMutableArray *arr0=[NSMutableArray array]; NSMutableArray *arr1=[NSMutableArray array]; NSMutableArray *arr2=[NSMutableArray array]; for(int i=0 ; i<10 ; i++) { MyItem *item=[[MyItem alloc] init]; item.classId_=@"0"; item.id_=[NSString stringWithFormat:@"%d",i]; item.title=[NSString stringWithFormat:@"title_%d",i]; [arr0 addObject:item]; for(int j=0;j<3;j++) { MyItem *item=[[MyItem alloc] init]; item.classId_=[NSString stringWithFormat:@"%d",i]; item.id_=[NSString stringWithFormat:@"%d",10+i*3+j+1]; item.title=[NSString stringWithFormat:@"title_%d",10+i*3+j+1]; [arr1 addObject:item]; for(int m=0;m<2;m++) { MyItem *item=[[MyItem alloc] init]; item.classId_=[NSString stringWithFormat:@"%d",10+i*3+j+1]; item.id_=[NSString stringWithFormat:@"%d",40+i*3*2+j*2+m+1]; item.title=[NSString stringWithFormat:@"title_%d",40+i*3*2+j*2+m+1]; [arr2 addObject:item]; } } } for (MyItem *item in arr2) { // NSLog(@"item.title = %@", item.title); } // for(int i=0 ;i<[arr0 count];i++) { MyItem *item0=[arr0 objectAtIndex:i]; item0.level=0; item0.subItems=[NSMutableArray array]; for(int j=0;j<[arr1 count];j++) { MyItem *item1=[arr1 objectAtIndex:j]; if([item1.classId_ isEqualToString:item0.id_]) { item1.level=1; item1.subItems=[NSMutableArray array]; for(int m=0;m<[arr2 count];m++) { MyItem *item2=[arr2 objectAtIndex:m]; if([item2.classId_ isEqualToString:item1.id_]) { item2.level=2; item2.subItems =[NSMutableArray array]; [item1.subItems addObject:item2]; } } [item0.subItems addObject:item1]; } } [_tableViewData addObject:item0]; } } - (NSMutableArray *) insertCellPaths:(NSIndexPath *)indexPath { NSMutableArray * insertCellPaths; insertCellPaths = [NSMutableArray array]; MyItem * item; item = [_tableViewData objectAtIndex:indexPath.row]; for (int i = 0; i< [item.subItems count]; i++) { MyItem *insertItem; insertItem = [item.subItems objectAtIndex:i]; [_tableViewData insertObject:insertItem atIndex:indexPath.row+i+1 ]; [insertCellPaths addObject:[NSIndexPath indexPathForRow:indexPath.row+i+1 inSection:0]]; } item.isSubItemOpen = YES; return insertCellPaths; } - (NSMutableArray *) cascadingInsertCellPaths:(NSIndexPath *)indexPath { [treeItemsToInsert removeAllObjects]; MyItem * item; item = [_tableViewData objectAtIndex:indexPath.row]; for (int i = 0; i < [item.subItems count]; i++) { MyItem * insertItem; insertItem = [item.subItems objectAtIndex:i]; NSLog(@"insert %@",insertItem); NSIndexPath *path = [NSIndexPath indexPathForRow:[_tableViewData indexOfObject:item] inSection:0]; [_tableViewData insertObject:insertItem atIndex:path.row +1+i]; [self cascadingInsertPaths:insertItem]; [treeItemsToInsert addObject:[NSIndexPath indexPathForRow:path.row+i+1 inSection:0]]; } // [self cascadingInsertPaths:item]; item.isSubItemOpen = YES; return treeItemsToInsert; } - (void) cascadingInsertPaths:(MyItem *)item { for (int i = 0; i < [item.subItems count] && item.isCascadeOpen ; i++) { MyItem * item1; item1 = [item.subItems objectAtIndex:i]; NSLog(@"insert %@",item1); NSIndexPath *path = [NSIndexPath indexPathForRow:[_tableViewData indexOfObject:item] inSection:0]; [_tableViewData insertObject:item1 atIndex:path.row +1+i]; [self cascadingInsertPaths:item1]; [treeItemsToInsert addObject:[NSIndexPath indexPathForRow:path.row+i+1 inSection:0]]; item.isSubItemOpen = YES; } } - (NSMutableArray *) cascadingDeletePaths:(NSIndexPath *)indexPath { [treeItemsToRemove removeAllObjects]; MyItem * item; item = [_tableViewData objectAtIndex:indexPath.row]; [self cascadingDeleteCellPaths:item]; NSMutableIndexSet * set; set = [NSMutableIndexSet indexSet]; for (int i = 0; i < [treeItemsToRemove count]; i++) { NSIndexPath *index; index = [treeItemsToRemove objectAtIndex:i]; [set addIndex:index.row]; } item.isSubItemOpen = NO; [_tableViewData removeObjectsAtIndexes:set]; return treeItemsToRemove; } - (void) cascadingDeleteCellPaths:(MyItem *)item { for (int i = 0; i < [item.subItems count] && item.isSubItemOpen ; i++) { MyItem * item1; item1 = [item.subItems objectAtIndex:i]; NSLog(@"sub %@",item1); NSIndexPath *path = [NSIndexPath indexPathForRow:[_tableViewData indexOfObject:item1] inSection:0]; [self cascadingDeleteCellPaths:item1]; [treeItemsToRemove addObject:path]; item1.isSubItemOpen = NO; } } - (NSMutableArray *) deleteCellPaths: (NSIndexPath *)indexPath { NSMutableArray * deleteCellPaths; deleteCellPaths = [NSMutableArray array]; MyItem * item; item = [_tableViewData objectAtIndex:indexPath.row]; for (int i = 0; i< [item.subItems count]; i++) { MyItem *deleteItem; deleteItem = [item.subItems objectAtIndex:i]; [deleteCellPaths addObject:[NSIndexPath indexPathForRow:indexPath.row+i+1 inSection:0]]; } [_tableViewData removeObjectsInRange: NSMakeRange(indexPath.row+1, [item.subItems count])]; item.isSubItemOpen = NO; return deleteCellPaths; } - (NSMutableArray *) insertCellPaths:(MyItem *)item rowAtIndexPath :(NSIndexPath *)indexPath { NSMutableArray * insertCellPaths; insertCellPaths = [NSMutableArray array]; for (int i = 0; i< [item.subItems count]; i++) { MyItem *insertItem; insertItem = [item.subItems objectAtIndex:i]; [_tableViewData insertObject:insertItem atIndex:indexPath.row+i+1 ]; [insertCellPaths addObject:[NSIndexPath indexPathForRow:indexPath.row+i+1 inSection:0]]; } return insertCellPaths; } @end ```
/content/code_sandbox/BigShow1949/Classes/08 - UIKit/UIScrollView/MutableMenuTableView/menuData/MenuData.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,657