界面两侧分离
来源:互联网 发布:淘宝女装一件代发厂家 编辑:程序博客网 时间:2024/04/30 02:11
s
Appdalagate.h方法中
#import "AppDelegate.h"
#import "CurtainViewController.h"
@implementation AppDelegate
@synthesize window=_window;
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
//简介的设置了初始化,和对界面的权限的
self.window.rootViewController=[[CurtainViewController alloc]init];
// CurtainViewController *curtainViewcontroler=[[CurtainViewController alloc]initWithNibName:CurtainViewController bundle:nil];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
在CurtainViewController.h类中实现方法
#import "CurtainViewController.h"
#import "DemoViewControler.h"
#import "UIViewController+RECurtainViewController.h"
//类别 类似是(要继承的类名 和新生成的类名)
@interface CurtainViewController ()
@end
@implementation CurtainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//对背景的设置 如果是真为 设置为11.jpg 假为其他的颜色
self.view.backgroundColor=UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone?
[UIColor colorWithPatternImage:[UIImage imageNamed:@"11.jpg"]]:[UIColor grayColor];
//按钮的位置的设置 点击事件 和显示
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake((self.view.frame.size.width-200)/2,self.view.frame.size.height/2-30,200,44);
[button setTitle:@"水平" forState:UIControlStateNormal];
[button addTarget:self action:@selector(dismisshorizontalPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
//水平 的方法的
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake((self.view.frame.size.width - 200) / 2, self.view.frame.size.height / 2 + 30, 200, 44);
[button setTitle:@"Dismiss Vertical" forState:UIControlStateNormal];
[button addTarget:self action:@selector(dismissVerticalPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
return self;
}
//事件发生 要调用的界面初始化 和调用重构的方法
-(void)dismisshorizontalPressed{
DemoViewControler *test=[[DemoViewControler alloc]init];
[self curtainRevealViewController:test transitionStyle:RECurtainTransitionHorizontal];
}
- (void)dismissVerticalPressed
//水平的方法的事件处理
{
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped]];
[self curtainRevealViewController:nav transitionStyle:RECurtainTransitionVertical];
}
在DemoViewControler.m 中实现的方法
#import "DemoViewControler.h"
#import "CurtainViewController.h"
#import "UIViewController+RECurtainViewController.h"
@interface DemoViewControler ()
@end
@implementation DemoViewControler
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//初始化进入第二个界面的背景和按钮的设置 按钮的点击事件
UIImageView *backgroundimage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"22.jpg"]];
[self.view addSubview:backgroundimage];
UIButton *button
=[UIButton buttonWithType:UIButtonTypeRoundedRect ];
button.frame=CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height/2-20, 200, 44);
[button setTitle:@"Test Button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(pressbutton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Custom initialization
}
return self;
}
-(void)pressbutton{
//按钮的点击的事件 第二界面的初始化 并调用重构的方法
CurtainViewController *test = [[CurtainViewController alloc] init];
[self curtainRevealViewController:test transitionStyle:RECurtainTransitionHorizontal];
}
//屏幕是否可以旋转'
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在类中 实现的协议 -----UIViewController (RECurtainViewController)
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
//用枚举的方法来判断水平还是垂直方向
typedef enum _RECurtainTransitionStyle {
RECurtainTransitionHorizontal = 0,
RECurtainTransitionVertical = 1
} RECurtainTransitionStyle;
@interface UIViewController (RECurtainViewController)
//界面的跳转用到的重构方法
- (void)curtainRevealViewController:(UIViewController *)viewControllerToReveal transitionStyle:(RECurtainTransitionStyle)transitionStyle;
#import "UIViewController+RECurtainViewController.h"
#import "AppDelegate.h"
@implementation UIViewController (RECurtainViewController)
- (UIImage *)imageWithView:(UIView *)view
{//
//选择不否是透明的图形
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
//重构的方法
- (void)curtainRevealViewController:(UIViewController *)viewControllerToReveal transitionStyle:(RECurtainTransitionStyle)transitionStyle
{
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
UIImage *selfPortrait = [self imageWithView:appDelegate.window];
UIImage *controllerScreenshot = [self imageWithView:viewControllerToReveal.view];
//初始化
UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, selfPortrait.size.width, selfPortrait.size.height)];
coverView.backgroundColor = [UIColor blackColor];
[appDelegate.window addSubview:coverView];//用代理来显示当期的图像
int offset = 20;
if (controllerScreenshot.size.height == [UIScreen mainScreen].bounds.size.height) {
offset = 0;
}
float padding = [UIScreen mainScreen].bounds.size.width * 0.1;
//初始化了一个图像的对象
UIImageView *fadedView = [[UIImageView alloc] initWithFrame:CGRectMake(padding, padding + offset, controllerScreenshot.size.width - padding * 2, controllerScreenshot.size.height - padding * 2 - 20)];
fadedView.image = controllerScreenshot;
fadedView.alpha = 0.4;
[coverView addSubview:fadedView];
UIImageView *leftCurtain = [[UIImageView alloc] initWithFrame:CGRectNull];
leftCurtain.image = selfPortrait;
leftCurtain.clipsToBounds = YES;
UIImageView *rightCurtain = [[UIImageView alloc] initWithFrame:CGRectNull];
rightCurtain.image = selfPortrait;
rightCurtain.clipsToBounds = YES;
if (transitionStyle == RECurtainTransitionHorizontal) {
leftCurtain.contentMode = UIViewContentModeLeft;
leftCurtain.frame = CGRectMake(0, 0, selfPortrait.size.width / 2, selfPortrait.size.height);
rightCurtain.contentMode = UIViewContentModeRight;
rightCurtain.frame = CGRectMake(selfPortrait.size.width / 2, 0, selfPortrait.size.width / 2, selfPortrait.size.height);
} else {
leftCurtain.contentMode = UIViewContentModeTop;
leftCurtain.frame = CGRectMake(0, 0, selfPortrait.size.width, selfPortrait.size.height / 2);
rightCurtain.contentMode = UIViewContentModeBottom;
rightCurtain.frame = CGRectMake(0, selfPortrait.size.height / 2, selfPortrait.size.width, selfPortrait.size.height / 2);
}
[coverView addSubview:leftCurtain];
[coverView addSubview:rightCurtain];
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
if (transitionStyle == RECurtainTransitionHorizontal) {
leftCurtain.frame = CGRectMake(- selfPortrait.size.width / 2, 0, selfPortrait.size.width / 2, selfPortrait.size.height);
rightCurtain.frame = CGRectMake(selfPortrait.size.width, 0, selfPortrait.size.width / 2, selfPortrait.size.height);
} else {
leftCurtain.frame = CGRectMake(0, - selfPortrait.size.height / 2, selfPortrait.size.width, selfPortrait.size.height / 2);
rightCurtain.frame = CGRectMake(0, selfPortrait.size.height, selfPortrait.size.width, selfPortrait.size.height / 2);
}
} completion:nil];
[UIView animateWithDuration:0.3 delay:0.5 options:UIViewAnimationCurveEaseIn animations:^{
fadedView.frame = CGRectMake(0, offset, controllerScreenshot.size.width, controllerScreenshot.size.height);
fadedView.alpha = 1;
} completion:^(BOOL finished){
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.window.rootViewController = viewControllerToReveal;
[leftCurtain removeFromSuperview];
[rightCurtain removeFromSuperview];
[fadedView removeFromSuperview];
[coverView removeFromSuperview];
}];
}
- 界面两侧分离
- 界面与代码分离
- 界面程序分离思路
- 界面和逻辑分离
- 逻辑与界面相分离
- 数据和界面分离思想
- 一个内容+界面+样式分离的例子
- 界面与程序分离 --- MIS开发新方法
- 界面与程序分离---MIS开发新方法
- 界面与程序分离--MIS开发新方法
- 使用xrc分离界面与代码
- VB6实现界面与功能代码分离
- 学习界面与业务分离有感
- GUI进化--数据与界面分离
- PyQt4--QThread实现界面与算法分离
- 界面层与业务逻辑层分离
- QSS与Qt主程序做到界面分离
- 界面层与业务逻辑层分离
- Linux学习记录——变量的设置规则
- linux2.6内核Makefile简单语法与应用
- 数组中只出现一次的一个数
- WebBrowser.ExecWB控件说明
- oracle中非常有用的查询语句
- 界面两侧分离
- java秒数转换成标准的北京时间
- 原子操作(atomic operation)
- javaSE-IO补充 File类
- live555实现Rtp码流读到一帧数据怎么传递客户端
- Java -- JDBC 数据库连接池
- get post 区别详解及引发中文乱码问题
- svc: failed to register lockdv1 RPC service (errno 111)
- cocos2dx 49种动作