IOS 实现简单抽屉效果
来源:互联网 发布:淘宝网热卖怎么加入 编辑:程序博客网 时间:2024/05/23 02:01
//// CustomView.h// test04抽屉效果//// Created by mouweng on 17/8/25.// Copyright © 2017年 mouweng. All rights reserved.//#import <UIKit/UIKit.h>@interface CustomView : UIView{ CGPoint openPointCenter; CGPoint closePointCenter;}-(id)initWithView:(UIView*)contentview parentView:(UIView*) parentview;@property (nonatomic, strong) UIView *parentView; //抽屉视图的父视图@property (nonatomic, strong) UIView *contenView; //抽屉显示内容的视图@end
//// CustomView.m// test04抽屉效果//// Created by mouweng on 17/8/25.// Copyright © 2017年 mouweng. All rights reserved.//#import "CustomView.h"#define OPENCENTERX 220.0#define DIVIDWIDTH 70.0 //OPENCENTERX 对应确认是否打开或关闭的分界线。@implementation CustomView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;}- (id)initWithView:(UIView *)contentview parentView:(UIView *)parentview{ self = [super initWithFrame:CGRectMake(0,0,contentview.frame.size.width, contentview.frame.size.height)]; if (self) { self.contenView = contentview; self.parentView = parentview; [self addSubview:contentview]; UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self addGestureRecognizer:panGestureRecognizer]; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [self addGestureRecognizer:tapGestureRecognizer]; openPointCenter = CGPointMake(self.parentView.center.x + OPENCENTERX, self.parentView.center.y); //NSLog(@"openPointCenter x:%f, openPointCenter y:%f",openPointCenter.x,openPointCenter.y); } return self;}-(void) handlePan:(UIPanGestureRecognizer*) recognizer{ CGPoint translation = [recognizer translationInView:self.parentView]; float x = self.center.x + translation.x; //NSLog(@"translation x:%f", translation.x); if (x < self.parentView.center.x) { x = self.parentView.center.x; } self.center = CGPointMake(x, openPointCenter.y); if(recognizer.state == UIGestureRecognizerStateEnded) { [UIView animateWithDuration:0.75 delay:0.01 options:UIViewAnimationCurveEaseInOut animations:^(void) { if (x > openPointCenter.x - DIVIDWIDTH) { self.center = openPointCenter; }else{ self.center = CGPointMake(openPointCenter.x - OPENCENTERX, openPointCenter.y); } }completion:^(BOOL isFinish){ }]; } [recognizer setTranslation:CGPointZero inView:self.parentView];}-(void) handleTap:(UITapGestureRecognizer*) recognizer{ [UIView animateWithDuration:0.75 delay:0.01 options:UIViewAnimationTransitionCurlUp animations:^(void){ self.center = CGPointMake(openPointCenter.x - OPENCENTERX, openPointCenter.y); }completion:nil]; }@end
//// ViewController.m// test04抽屉效果//// Created by mouweng on 17/8/25.// Copyright © 2017年 mouweng. All rights reserved.//#import "ViewController.h"#import "CustomView.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); //NSLog(@"w:%f, h:%f", rect.size.width, rect.size.height); UIImageView *imageleft = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"left.jpg"]]; imageleft.frame = rect; [self.view addSubview:imageleft]; UIView *contentView = [[UIView alloc] initWithFrame:rect]; UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"index.jpg"]]; imageView.frame = rect; [contentView addSubview:imageView]; CustomView *customView = [[CustomView alloc] initWithView:contentView parentView:self.view]; [[customView layer] setShadowOffset:CGSizeMake(10, 10)]; [[customView layer] setShadowRadius:20]; [[customView layer] setShadowOpacity:1]; [[customView layer] setShadowColor:[UIColor blackColor].CGColor]; [self.view addSubview:customView]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
阅读全文
0 0
- iOS-简单抽屉效果实现
- iOS 简单实现抽屉效果
- IOS 实现简单抽屉效果
- IOS 简单抽屉效果
- ios 抽屉效果实现
- iOS实现抽屉效果
- iOS 抽屉效果实现
- iOS 【UIKit-简单抽屉效果】
- iOS中 超简单抽屉效果(MMDrawerController)的实现
- iOS中 简单抽屉效果(MMDrawerController)的实现
- iOS中 超简单抽屉效果(MMDrawerController)的实现
- 抽屉效果的简单实现
- [ios]自定义简单的抽屉效果
- iOS最简单的抽屉效果
- 利用DrawerLayout实现简单的抽屉效果
- 【UI基础】抽屉效果简单实现
- 实现IOS版的抽屉效果
- 【代码笔记】iOS-抽屉效果的实现
- Ubuntu14.04安装CPU版SSD(Single Shot MultiBox Detector)/Caffe版本(二)
- [新手编程训练项目]001——C语言文本合并01
- corejava_static-final- abstract-接口
- 波特五力模型(Porter's Five Forces Model)
- LVS+Keepalived
- IOS 实现简单抽屉效果
- MySQL学习之使用视图
- 圆角边框和背景
- C++文件操作——MFC打开文件与保存文件
- Aizu
- Ubuntu14.04安装CPU版SSD(Single Shot MultiBox Detector)/Caffe版本(三)
- P1443 马的遍历
- MOOC清华《面向对象程序设计》第4章:delete禁止自动类型转换实验
- 初学python-3