前言
pop,present都是iOS中界面弹出的方式
UIColor,CGColor是iOS中的颜色
present
简介:
present和dismiss对应。present用于推出新的界面,dismiss用于返回上一界面
present和dismiss只能用于跳转至下一界面和返回上一界面
present弹出的视图是模态视图,所以只能逐级返回。
present一般用于不同业务的界面切换
使用方法:
// text.9.15
//
// Created by 王璐 on 2022/9/15.
//
#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"loadView 1");
self.view.backgroundColor = [UIColor orangeColor];
UIButton* button = [[UIButton alloc] init];
button.frame = CGRectMake(100, 100, 100, 50);
[button setTitle:@"跳转" forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view.
}
- (void)press{
SecondViewController* second = [[SecondViewController alloc] init];
[self presentViewController:second animated:YES completion:nil];
}
// SecondViewController.m
// text.9.15
//
//
#import "SecondViewController.h"
#import "ViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"loadView 2");
self.view.backgroundColor = [UIColor greenColor];
UIButton* button = [[UIButton alloc] init];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor blueColor];
[button setTitle:@"返回" forState:UIControlStateNormal];
[button addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view.
}
- (void)press{
ViewController* First = [[ViewController alloc] init];
[self dismissViewControllerAnimated:YES completion:nil];
}
使用方法present弹出的视图都称之为模态视图,模态视图出现的场景一般是临时弹出的场景,比如登陆窗口,注册窗口。
动画效果的设置
注意一定添加
second.modalPresentationStyle = UIModalPresentationFullScreen才可以设置动画
SecondViewController* second = [[SecondViewController alloc] init];
second.modalPresentationStyle = UIModalPresentationFullScreen;
//出现时从下到上,消失时从上到下。默认效果
//second.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//边角翻页效果
//second.modalTransitionStyle = UIModalTransitionStylePartialCurl;
//淡入淡出效果
//second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//水平翻转,开始时从右至左,返回时从左至右
//second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
push
简介:
push和pop对应
push由视图栈控制,可以返回任一级视图,不像present只能返回上一级视图
push一般用于同一业务不同界面切换。例如从微信“消息”界面跳转至微信”我的“界面
// SceneDelegate.m
// text.9.15
//
//
#import "SceneDelegate.h"
#import "ViewController.h"
@interface SceneDelegate ()
@end
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
self.window = [[UIWindow alloc]initWithWindowScene:(UIWindowScene*)scene];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
[self.window makeKeyAndVisible];
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
}
// ViewController.m
// text.9.15
//
//
#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"loadView 1");
self.view.backgroundColor = [UIColor whiteColor];
UIButton* button = [[UIButton alloc] init];
button.frame = CGRectMake(100, 100, 100, 50);
[button setTitle:@"跳转" forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view.
}
- (void)press{
SecondViewController* second = [[SecondViewController alloc] init];
[self.navigationController pushViewController:second animated:YES];
}
@end
// SecondViewController.m
// text.9.15
//
//
#import "SecondViewController.h"
#import "ViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"loadView 2");
self.view.backgroundColor = [UIColor whiteColor];
UIButton* button = [[UIButton alloc] init];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor blueColor];
[button setTitle:@"返回" forState:UIControlStateNormal];
[button addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view.
}
- (void)press{
//ViewController* First = [[ViewController alloc] init];
[self.navigationController popoverPresentationController];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
使用push跳转到第二界面时,第二界面顶部会出现一个导航栏,左上方有<Back按钮可以直接返回第一界面
UIColor,CGColor,ClColor
UIColor
UIColor是继承于UIKit中储存颜色信息的一个重要的类,一个UIColor对象包括了颜色和透明度的值。
UIColor可以直接创建一些常见的颜色,这些颜色的色彩空间也不尽相同(白色和黑色是kCGColorSpaceDeviceGray,红色的色彩空间是kCGColorSpaceDeviceRGB)。
此外UIColor还有两个重要的属性:一个是CGColor,一个是CIColor(5.0之后添加)。
CGColor
CGColor主要用于CoreGaphics框架之中,CGColor其实是个结构体,而我们通常在使用的CGColor的时候使用的是它的引用类型CGColorRef。CGColor主要由CGColorSapce和Color Components两个部分组成。
同样的颜色组成,如果颜色空间不同的话,解析出来的结果可能会有所不同。
ClColor
CIColor主要是用于和CoreImage框架中其他类,比如CIFilter,CIContext以及CIImage。CIColor中颜色值的范围是0.0-1.0之间,0.0代表该颜色分量为最小值,1.0代表改颜色分量为最大值。其中alpha值的范围也是0.0到1.0之间,0.0代表全透明,1.0代表完全不透明,同时CIColor的颜色分量通常都是没有乘以alpha值。
可以使用initWithCGColor:函数,通过CGColor创建一个CIColor。其中传入的CGColorRef对象可以使任何任何颜色空间,但是Core Image框架会在传入filter kernel之前把所有的颜色空间转换到core image工作颜色空间。core image工作颜色空间使用三个颜色分量加上一个alpha分量组成(其实就是kCGColorSpaceDeviceRGB)