1.搜索关键字高亮显示
image.png2.动态改变tableHeaderView的高度
表头展开折叠.gif headAllView.tapChangeFrame = ^(void) {
[weakSelf.Tb beginUpdates];
[weakSelf.Tb setTableHeaderView:weakHeadAllView];
[weakSelf.Tb endUpdates];
};
self.Tb.tableHeaderView = headAllView;
关键效果设置:在改变tableHeaderView的高度后,再手动调用下 Tb 的 setTableHeaderView方法。
3.MBProgressHUD文字多时换行展示
@implementation MBProgressHUD (CXRExpand)
+ (void)showText:(NSString *)text image:(NSString *)image toView:(UIView *)view {
if (view == nil) view = [[UIApplication sharedApplication] keyWindow];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
if (text.length>15) {
hud.detailsLabelText = text;
}else{
hud.labelText =text;
}
hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", image]]];
hud.mode = MBProgressHUDModeCustomView;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:1.5];
}
修改MBProgressHUD里面的源文件即可实现。
4.扫描身份证快速读取信息、扫描银行卡获取卡号
银行卡扫描
5.UIButton文本竖着排列
你可能找不到这样的设置,但是可以这样简单的实现。
[selectButton setTitle:@"查\n询" forState:UIControlStateNormal];
selectButton.titleLabel.numberOfLines = 0;
6. 输入框后面带上单位
- (void)setMyRightText :(NSString *)rightText;
{
if (rightText.length>0) {
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0,0, Scale_X(60), Scale_Y(20))];
label.textColor=GrayTextColor;
[label setBackgroundColor:[UIColor clearColor]];
label.text=rightText;
[label setFont:[UIFont fontWithName:@"Helvetica" size:MEDIUM_FONT]];
label.textAlignment = NSTextAlignmentRight;
self.rightViewMode = UITextFieldViewModeAlways;
self.rightView = label ;
}
}
可以在自定义的UITextFeild的类中实现如下方法,关键是rightViewMode的设置,默认是不显示的。
7. 为Cell增加动效
实现方法是在TableView加载后增加整体的动效,通过循环和延迟,让每个Cell从不同的时间开始经历相同的时间动效结束。
- (void)viewDidAppear:(BOOL)animated
{
[self animateStart];
}
- (void)animateStart
{
NSArray *array = [Tb visibleCells];
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UITableViewCell *cell = (UITableViewCell*)obj;
cell.transform = CGAffineTransformMakeTranslation(0, Tb.bounds.size.height);
[UIView animateWithDuration:1 delay:0.05*idx usingSpringWithDamping:0.8 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:^{
cell.transform = CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
}];
}];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.frame = CGRectMake(-Tb.bounds.size.width, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
[UIView animateWithDuration:0.2 delay:0.2*indexPath.row options:UIViewAnimationOptionCurveEaseIn animations:^{
cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
} completion:^(BOOL finished) {
}];
}
cell点击.gif
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [Tb cellForRowAtIndexPath:indexPath];
NSTimeInterval animationDuration =0.05;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
cell.transform = CGAffineTransformMakeScale( 0.9, 0.9);
[UIView commitAnimations];
}
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [Tb cellForRowAtIndexPath:indexPath];
NSTimeInterval animationDuration =1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
cell.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
上面两个方法调用后,会调用这个方法。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
}
8. 网易顶部类似多类目选择视图
1.创建很多ChildViewController
//推荐
CY1ViewController *message = [[CY1ViewController alloc] init];
message.title = @"推荐";
[self addChildViewController:message];
//赛事
CY2ViewController *comp = [[CY2ViewController alloc] init];
comp.title = @"赛事";
[self addChildViewController:comp];
.....
2.创建很多对应的Button
for (int i = 0; i < self.childViewControllers.count; ++i) {
UIViewController *vc = self.childViewControllers[i];
UIButton *btn = [[UIButton alloc] init];;
btn.frame = CGRectMake(btnW * i , 0, btnW, btnH);
[btn setTitle:vc.title forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(topTitleBtnClick:) forControlEvents:UIControlEventTouchDown];
btn.tag = i;
[view addSubview:btn];
if (btn.tag == 0) {
[self topTitleBtnClick:btn];
}
[self.titleButton addObject:btn]; //一个数组
}
3.Button的点击事件,放大当前的按钮恢复上一个点击的按钮,并滚动SC。
- (void)selctedBtn:(UIButton *)btn
{
[_selectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self setupTitleButtonCenter:btn];
_selectBtn.transform = CGAffineTransformIdentity;
btn.transform = CGAffineTransformMakeScale(1.3, 1.3);
//上次点击的按钮
_selectBtn = btn;
}
- (void)setUpOnechildController:(UIButton *)btn
{
UIViewController *vc = self.childViewControllers[btn.tag];
if (!vc.view.superview) {
vc.view.frame = CGRectMake(btn.tag * kScreenW, 64, kScreenW, kScreenH - 64);
[self.contentScroll addSubview:vc.view];
};
self.contentScroll.contentOffset = CGPointMake(btn.tag *kScreenW, 0);
}
9.左右大面积侧滑
侧滑.gif要实现这样的效果,先看图层关系:
WWSideslipViewController是一个VC,在WWSideslipViewController的View上依次放上如下子视图:
- 星空背景ImageView;
- LeftVC的View
- RightVC的View
- MainVC的View(效果图中是放了一个QQ主页的截图)
给MainVC的View加手势,根据手势,动态改变MainVC的View的外形并隐藏/展示 LeftVC的View或者 rightVC的View即可。
WWSideslipViewController 中
//滑动手势
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[mainControl.view addGestureRecognizer:pan];
//单击手势
sideslipTapGes= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handeTap:)];
[sideslipTapGes setNumberOfTapsRequired:1];
[mainControl.view addGestureRecognizer:sideslipTapGes];
leftControl.view.hidden = YES;
righControl.view.hidden = YES;
[self.view addSubview:leftControl.view];
[self.view addSubview:righControl.view];
[self.view addSubview:mainControl.view];
10.点击cell中的UIImageView全屏展示并关闭
点击.gifactionTap 是cell中的图片上加的手势事件。
-(void)actionTap:(UITapGestureRecognizer *)sender{
CGPoint location = [sender locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
UIImageView *imageView=(UIImageView *)[cell.contentView viewWithTag:9999];
//记录下点击的图片位置
frame_first=CGRectMake(cell.frame.origin.x+imageView.frame.origin.x, cell.frame.origin.y+imageView.frame.origin.y-self.tableView.contentOffset.y, imageView.frame.size.width, imageView.frame.size.height);
fullImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height)];
fullImageView.backgroundColor=[UIColor blackColor];
fullImageView.userInteractionEnabled=YES;
[fullImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap2:)]]; //添加轻击手势
fullImageView.contentMode=UIViewContentModeScaleAspectFit;
if (![fullImageView superview]) {
fullImageView.image=imageView.image;
[self.view.window addSubview:fullImageView];
fullImageView.frame=frame_first;
[UIView animateWithDuration:0.5 animations:^{
fullImageView.frame=CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height);
} completion:^(BOOL finished) {
[UIApplication sharedApplication].statusBarHidden=YES;
}];
}
}
-(void)actionTap2:(UITapGestureRecognizer *)sender{
[UIView animateWithDuration:0.5 animations:^{
fullImageView.frame=frame_first;
} completion:^(BOOL finished) {
[fullImageView removeFromSuperview];
}];
[UIApplication sharedApplication].statusBarHidden=NO;
}
点评:其实这样的效果并不难,如果把cell中的UIImageView换成UIbutton就很简单了,很容易找到那个image,可是那样的话需要点击进去才能触发事件,而不是轻击。也算给我们提供一种根据手势点击获取cell的思路。
网友评论