简单侧滑
来源:互联网 发布:淘宝联盟手机版5.2 编辑:程序博客网 时间:2024/05/01 09:21
@class LeftView;
@protocol LeftViewDelegate <NSObject>
- (void)LeftView:(LeftView *)view selectedIndex:(NSInteger)integer;
@end
@interface LeftView : UIView
<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, weak) id<LeftViewDelegate>delegate;
@property (nonatomic, strong) NSArray *viewConttrollers;
- (id)initWithArray:(NSArray *)array;
@end
#import "LeftView.h"
#import <QuartzCore/QuartzCore.h>
@implementation LeftView
- (id)initWithArray:(NSArray *)array
{
self = [super initWithFrame:CGRectMake(0, 0, 320, 480)];
if (self) {
self.backgroundColor=[UIColor colorWithRed:239.0/255 green:250.0/255 blue:233.0/255 alpha:1];
self.viewConttrollers=array;
UILabel *titleLabel_=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
titleLabel_.backgroundColor=[UIColor scrollViewTexturedBackgroundColor];
titleLabel_.layer.shadowColor=[UIColor blackColor].CGColor;
titleLabel_.layer.shadowOffset=CGSizeMake(-2, -5);
titleLabel_.layer.shadowOpacity=0.5;
titleLabel_.text=@"此处可放置logo和一些按扭";
titleLabel_.font=[UIFont boldSystemFontOfSize:20];
//
titleLabel_.textAlignment=NSTextAlignmentCenter;
titleLabel_.textColor=[UIColor whiteColor];
[self addSubview:titleLabel_];
UITableView *tableView_=[[UITableView alloc] initWithFrame:CGRectMake(0, 50, 260, 435)];
tableView_.backgroundColor=[UIColor clearColor];
tableView_.separatorStyle=UITableViewCellSeparatorStyleNone;
tableView_.rowHeight=50;
tableView_.delegate=self;
tableView_.dataSource=self;
[self addSubview:tableView_];
NSIndexPath *indexPath_=[NSIndexPath indexPathForRow:0 inSection:0];
[tableView_ selectRowAtIndexPath:indexPath_ animated:YES scrollPosition:UITableViewScrollPositionNone];
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.viewConttrollers.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellString_=@"tableCell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString_];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellString_];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
UIViewController *viewController_=self.viewConttrollers[indexPath.row];
cell.imageView.image=viewController_.tabBarItem.image;
cell.textLabel.text=viewController_.tabBarItem.title;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if ([self.delegate respondsToSelector:@selector(LeftView:selectedIndex:)]) {
[self.delegate LeftView:self selectedIndex:indexPath.row];
}
}
- (void)btnClick{
NSLog(@"left");
}
@end
#import "ViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "LeftView.h"
@interface ViewController ()<LeftViewDelegate>
@property (nonatomic, strong) UIView *transitionView;
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (UIView *view_ in self.view.subviews) {
if ([view_ isKindOfClass:[UITabBar class]]) {
[view_ removeFromSuperview];
}
else{
self.transitionView=view_;
}
}
self.transitionView.frame=CGRectMake(0, 0, 320, 480);
//左划
UISwipeGestureRecognizer *swipeLeftGesture_=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGesterClick:)];
swipeLeftGesture_.direction=UISwipeGestureRecognizerDirectionLeft;//不设置默认为右
[self.transitionView addGestureRecognizer:swipeLeftGesture_];
swipeLeftGesture_=nil;
//右划
UISwipeGestureRecognizer *swipeRightGesture_=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGesterClick:)];
[self.transitionView addGestureRecognizer:swipeRightGesture_];
swipeRightGesture_=nil;
OneViewController *oneViewController_=[[OneViewController alloc] init];
UINavigationController *oneNav_=[[UINavigationController alloc] initWithRootViewController:oneViewController_];
oneViewController_=nil;
TwoViewController *twoViewController_=[[TwoViewController alloc] init];
UINavigationController *twoNav_=[[UINavigationController alloc] initWithRootViewController:twoViewController_];
twoViewController_=nil;
self.viewControllers=@[oneNav_, twoNav_];
oneNav_=nil;
twoNav_=nil;
LeftView *leftView_=[[LeftView alloc] initWithArray:self.viewControllers];
leftView_.delegate=self;
[self.view insertSubview:leftView_ atIndex:0];
leftView_=nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showAndHiddenLeftView)
name:@"showAndHiddenLeftView"
object:nil];
}
- (void)swipeGesterClick:(UISwipeGestureRecognizer *)swipeGesture{
float x=self.transitionView.frame.origin.x;
if (swipeGesture.direction==UISwipeGestureRecognizerDirectionLeft && x>0) {
x=0;
[UIView beginAnimations:nil context:nil];
self.transitionView.frame=CGRectMake(x, 0, 320, 480);
[UIView commitAnimations];
}
else if (swipeGesture.direction==UISwipeGestureRecognizerDirectionRight && x==0) {
x=260;
[UIView beginAnimations:nil context:nil];
self.transitionView.frame=CGRectMake(x, 0, 320, 480);
[UIView commitAnimations];
}
}
- (void)showAndHiddenLeftView{
float x=self.transitionView.frame.origin.x;
if (x>0) {
x=0;
}
else{
x=260;
}
[UIView beginAnimations:nil context:nil];
self.transitionView.frame=CGRectMake(x, 0, 320, 480);
[UIView commitAnimations];
}
-(void)LeftView:(LeftView *)view selectedIndex:(NSInteger)integer{
self.selectedIndex=integer;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"showAndHiddenLeftView" object:nil];
}
@end
- 简单侧滑
- 简单侧滑
- 简单侧滑
- 简单的侧滑
- 简单的侧滑
- SlidingMenu 简单侧滑
- 简单侧滑
- SlidingMenu侧滑简单实现
- SlidingMenu侧滑简单实现
- 最简单侧滑实现
- 简单实现侧滑菜单
- DrawerLayout侧滑简单应用
- 一个简单的侧滑
- 简单导航+侧滑模板
- DrawerLayout实现简单的侧滑功能
- Android侧滑菜单栏简单实现
- UI实现简单的侧滑效果
- 最简单的侧滑效果DrawerLayout
- JAVA 中字符串的截取,要求不能截取半个汉字
- Linux 常用命令
- java面试题大全
- vi/vim使用进阶: quickfix
- java 中局部变量的初始值
- 简单侧滑
- 黑马程序员----String对象的创建的扩展
- 男生女生配(sdut 1470
- 网上报名系统初步设计
- C++ 虚函数表解析
- SQL面试题
- C语言变参函数的编写
- 黑马程序员-------.net基础知识九
- 内核中的 dev_emerg/dev_alert/dev_crit/dev_err/dev_warn/dev_notice/_dev_info