打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
IOS UI 第四篇:基本UI
ViewController 应用
再第一个XIB页面创建另一个XIB页面,并且通过按钮调用它
- (IBAction)GoSecond:(id)sender {
secondViewController *secVC = [[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
secVC.modalTransitionStyle = UIModalPresentationPageSheet;
[self presentViewController:secVC animated:YES completion:^{
NSLog(@"success ");
}];
}
在第二个XIB页面创建一个按钮,按钮PRESS返回第一个页面
- (IBAction)Backfirst:(id)sender {
[
self dismissViewControllerAnimated:YES completion:^{
NSLog(@"dismiss");
}];
}
创造生命周期函数:

-(
void)viewWillAppear:(BOOL)animated{
[
super viewWillAppear:animated];
NSLog(@"view will appear");
}
-(
void)viewDidAppear:(BOOL)animated{
[
super viewDidAppear:animated];
NSLog(@"view did appear");
}
-(
void)viewWillDisappear:(BOOL)animated{
[
super viewWillDisappear:animated];
NSLog(@"view will disappear");
}
-(
void)viewDidDisappear:(BOOL)animated{
[
super viewDidDisappear:animated];
NSLog(@"view did disappear");
}
页面切换方法:
secVC.modalTransitionStyle = UIModalPresentationPageSheet;
UIModalPresentationFullScreen = 0,
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
UIModalPresentationPageSheet,
UIModalPresentationFormSheet,
UIModalPresentationCurrentContext,
#endif
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
UIModalPresentationCustom,
UIModalPresentationNone = -
1,
做成如下图片,类型:
主视图代码:
#import "UserModel.h"
@interface Xib_1 : UIViewController
@property (nonatomic, weak) UserModel *model;
-(
void)sentRegistMessage:(UserModel *)user;
@end
- (IBAction)FirstButton:(id)sender {
Xib_2 *xib2 = [[Xib_2 alloc] initWithNibName:@"Xib_2" bundle:nil];
xib2.
parentVC = self;
xib2.
modalTransitionStyle = UIModalPresentationPageSheet;
[
self presentViewController:xib2 animated:YES completion:^{

}];
}

-(void)sentRegistMessage:(UserModel *)user{
self.Label_1.text = [NSString stringWithFormat:@"恭喜,注册成功,用户名:%@,密码:%@,请牢记,谢谢合作。", user.name, user.pass];
self.Label_1.numberOfLines = 0;
}
XIB2:
#import "Xib_1.h"

@interface Xib_2 : UIViewController
@property (nonatomic, weak) Xib_1 *parentVC;
@end
- (IBAction)Button_submit:(id)sender {
UserModel *model = [[UserModel alloc] init];
model.
name = _nameLabel.text;
model.
pass = _passLabel.text;
[
self.parentVC sentRegistMessage:model];
[
self dismissViewControllerAnimated:YES completion:^{
}];
}

UserModel:
@interface UserModel : NSObject
@property (nonatomic, copy)NSString *name;
@property (nonatomic, copy)NSString *pass;
@end
用协议可以限制权限:
小球移动的动画:
@implementation QFAppDelegate{
UIView *redView;
}

- (
BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//动画
redView=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
redView.backgroundColor=[UIColor redColor];
[
self.window addSubview:redView];

UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
[button
setTitle:@"开始动画" forState:UIControlStateNormal];
[button
setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button
addTarget:self action:@selector(startAnim:) forControlEvents:UIControlEventTouchUpInside];
button.
frame=CGRectMake(100, 400, 100, 44);
[
self.window addSubview:button];


self.window.backgroundColor = [UIColor whiteColor];
[
self.window makeKeyAndVisible];
return YES;
}
-(
void)startAnim:(id)sender{
[
UIView animateWithDuration:1 animations:^{
redView.frame=CGRectMake(100, 300, 150, 150);//大小位置
redView.transform=CGAffineTransformMakeRotation(M_PI_4);//角度
}
completion:^(BOOL finished) {
if (finished) {
[
UIView animateWithDuration:2 animations:^{
redView.transform=CGAffineTransformIdentity;//把变形还原
redView.frame=CGRectMake(100, 100, 100, 100);
}];
}
}];
}
如图,做一个三本书旋转的动画例子:
通过animateWithDuration:animations方法来实现动画旋转效果,方便,快捷!
代码如下:
- (void)viewDidLoad
{

[
super viewDidLoad];
[
self begin];
// Do any additional setup after loading the view from its nib.
}

-(
void)begin
{
imageView_3 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 50, 100, 150)];
imageView_2 = [[UIImageView alloc] initWithFrame:CGRectMake(200, 50, 100, 150)];
imageView_1 = [[UIImageView alloc] initWithFrame:CGRectMake(80, 110, 140, 200)];

imageView_1.image = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg"]];
imageView_2.image = [UIImage imageNamed:[NSString stringWithFormat:@"2.jpg"]];
imageView_3.image = [UIImage imageNamed:[NSString stringWithFormat:@"3.jpg"]];

[
_Subview addSubview:imageView_1];
[
_Subview addSubview:imageView_2];
[
_Subview addSubview:imageView_3];
[
_Subview bringSubviewToFront:imageView_1];

}
- (
IBAction)PrePress:(id)sender {
[
UIView animateWithDuration:1 animations:^{
[
_Subview sendSubviewToBack:imageView_3];
imageView_1.frame = CGRectMake(30, 50, 100, 150);
imageView_2.frame = CGRectMake(80, 110, 140, 200);
imageView_3.frame = CGRectMake(200, 50, 100, 150);
}
completion:^(BOOL finished) {
//imageView_2.frame = CGRectMake(30, 50, 100, 150);
[
_Subview bringSubviewToFront:imageView_2];
UIImageView *tmp;
tmp =
imageView_1;
imageView_1 = imageView_2;
imageView_2 = imageView_3;
imageView_3 = tmp;
}];

}
- (
IBAction)NextPress:(id)sender {

[
UIView animateWithDuration:1 animations:^{
[
_Subview sendSubviewToBack:imageView_2];
imageView_1.frame = CGRectMake(200, 50, 100, 150);
imageView_2.frame = CGRectMake(30, 50, 100, 150);
imageView_3.frame = CGRectMake(80, 110, 140, 200);
}
completion:^(BOOL finished) {
imageView_2.frame = CGRectMake(30, 50, 100, 150);
[
_Subview bringSubviewToFront:imageView_3];
UIImageView *tmp;
tmp =
imageView_1;
imageView_1 = imageView_3;
imageView_3 = imageView_2;
imageView_2 = tmp;
}];
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ios 关于 通过加载 xib 生成的view,调用 addsubviews,sub view的按钮 不相应点击事件的 问题
关于一个简单的复选框的定制
imageView添加响应事件
iOS开发之xib技巧介绍
三十而立,从零开始学ios开发(十):Multiview Applications(多个xib之前的切换)
iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服