移动开发iOS之如何在UI界面实现视图的交替
来源:互联网 发布:log4j配置打印sql语句 编辑:程序博客网 时间:2024/05/22 09:50
首先,在IOS中建立一个Single View Application;
在创建一个类Cocoa Touch Class,继承于ViewController类;
在ViewController写:
#import “ViewController.h”
#import “NextViewController.h”
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
//模态视图推送
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.translatesAutoresizingMaskIntoConstraints = NO;
[button setTitle:@”推送” forState:0];
[button addTarget:self action:@selector(pushAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
//给按钮添加约束来布局,即相当于frame的功能:
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
[self.view addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];[self.view addConstraint:constraint];constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:60];[self.view addConstraint:constraint];constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:30];[self.view addConstraint:constraint];
-(void)pushAction:(UIButton *)sender{
NextViewController *nextViewController = [[NextViewController alloc] init];
//模态视图过度动画
nextViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:nextViewController animated:YES completion:^{
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
在新建的类中这么写:
#import “ViewController.h”
@interface NextViewController : ViewController
@end
#import “NextViewController.h”
@interface NextViewController ()
@end
@implementation NextViewController
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor redColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.translatesAutoresizingMaskIntoConstraints = NO;[button setTitle:@"返回" forState:0];[button addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:button];NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];[self.view addConstraint:constraint];constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];[self.view addConstraint:constraint];constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:60];[self.view addConstraint:constraint];constraint = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:30];[self.view addConstraint:constraint];
}
-(void)popAction:(UIButton *)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- 移动开发iOS之如何在UI界面实现视图的交替
- 移动开发iOS之如何在UI相框里实现动画
- IOS开发(88)之动画之视图的移动
- iOS开发之iOS界面UI
- IOS开发UI-------视图的生命周期
- iOS开发之UI基础--纯代码自定义UItableviewcell实现一个简单的微博界面布局
- ioS开发之UI基础--使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
- JQuery 实现鼠标移动的动态交替
- iOS开发之UI控件——UIPickerView实现点菜系统界面布局
- UI之单个表视图的移动插入和删除
- iOS开发 UI 自定义视图
- iOS开发中如何在View视图中获取到该视图的控制器
- iOS开发-UI-应用管理实现九宫格界面
- iOS开发学习之#表视图#(3)移动行
- IOS视图之UI基础
- iOS ui界面vtf 开发
- iOS开发之开源UI界面类项目总结
- iOS UI界面之UIButton
- php isset()函数
- 剑指offer-树中两个节点的最低公共祖先
- Qt浅谈之三十三颜色列表
- AspectJ在测试中的应用
- 机器学习之特征选择
- 移动开发iOS之如何在UI界面实现视图的交替
- 阿里巴巴2015秋季笔试研发工程师JAVA
- Ilog、Drools、Jess规则引擎的Rule Language 对比
- pat(B) 1037. 在霍格沃茨找零钱(水题)
- poj1995-Raising Modulo (快速幂)
- 紧急通知英雄联盟90066游戏主播蒙山是大骗子
- 华为OJ(线性插值)
- 机房收费系统之窗体显示
- java线程池的使用,实现大量数据的更新操作