绘制图形的视图方式为_三角函数图象的平移变换

绘制图形的视图方式为_三角函数图象的平移变换iOS Programming – Views(视图 – 基本绘制,变换,平移,旋转,反转,倾斜)

大家好,又见面了,我是你们的朋友全栈君。

1. Views

A view (an object whose class is UIView or a subclass of UIView) knows how to draw itself into a rectangular area of the interface.

Your app has a visible interface thanks to views.

(eg: you can drag an interface widget, such as a UIButton, into a view in the nib editor;

when the app runs, the button appears, and works properly.

You can also manipulate views in powerful ways, in real time. Your code can do some or all of the

view’s drawing of itself)

A view is also a responder (UIView is a subclass of UIResponder).

This means that a view is subject to user interactions, such as taps and swipes.

A view can have subviews;

If a view is removed from the interface, its subviews are removed;

if a view is hidden (made invisible), its subviews are hidden;

if a view is moved, its subviews move with it; and other changes in a view are likewise

shared with its subviews.

A view may come from a nib, or you can create it in code.

On balance, neither approach is to be preferred over the other; it depends on your needs and inclinations and on the

overall architecture of your app.

 

2. The Window

The top of the view hierarchy is the app’s window.

It is an instance of UIWindow (or your own subclass), which is a UIView subclass.

Your app should have exactly one main window.  It is created at launch time and is never destroyed or replaced.

It occupies the entire screen and forms the background, and is the ultimate superview of, all your other visible views.

The window must fill the device’s screen.

This is done by setting the window’s frame to the screen’s bounds as the window is instantiated.

Objective-C:

UIWindow* w = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Swift(iOS8):

let w = UIWindow(frame: UIScreen.mainScreen().bounds)

Swift(iOS9):

// it’s sufficient to instantiate UIWindow with no frame
let w = UIWindow()

You will typically not put any view content manually and directly inside your main window.
Instead, you’ll obtain a view controller and assign it to the main window’s root ViewController property.

This causes the view controller’s main view (its view) to be made the one and only immediate subview of

your main window, which is the main window’s root view.

All other views in your main window will be subviews of the root view. Thus,

the root view is the highest object in the view hierarchy that the user will usually see.

Your app’s interface is not visible until the window, which contains it, is made the app’s
key window. This is done by calling the UIWindow instance method makeKeyAndVisible.

 

When addSubview: is called, the view is placed last among its superview’s subviews;
thus it is drawn last, meaning that it appears frontmost.

(最后绘制的,出现在最前面)

 

// it is legal to cycle through it and remove each subview one at a time
for (UIView* v in view.subviews)
    [v removeFromSuperview];

 

3. Visibility and Opacity(可见性与不透明度)

A view can be made invisible by setting its hidden property to YES, and visible again
by setting it to NO.

A view can be assigned a background color through its backgroundColor property. A
color is a UIColor;

A view whose background color is nil (the default) has a transparent background.

A view can be made partially or completely transparent through its alpha property: 1.0
means opaque, 0.0 means transparent, and a value may be anywhere between them,
inclusive.
This affects subviews: if a superview has an alpha of 0.5, none of its subviews
can have an apparent opacity of more than 0.5, because whatever alpha value they have
will be drawn relative to 0.5.
A view that is completely transparent (or very close to it) is like a view whose hidden is
YES: it is invisible, along with its subviews, and cannot (normally) be touched.

eg:

if a view displays an image and has a background color and its alpha is less than 1, the background color
will seep through the image (背景色将渗入图像).

 

4. Frame

A view’s frame property, a CGRect, is the position of its rectangle within its superview.
By default, the superview’s coordinate system will have the origin at its top left,
with the x-coordinate growing positively rightward and the y-coordinate growing positively downward.
(等同于Cocos2d-x中的UI坐标系,原点在左上角)

Setting a view’s frame to a different CGRect value repositions the view, or resizes it, or both.

例: 画3个部分重叠的视图 

Objective-C:

UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(113, 111, 132, 194)];
v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1];
UIView* v2 = [[UIView alloc] initWithFrame:CGRectMake(41, 56, 132, 194)];
v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1];
UIView* v3 = [[UIView alloc] initWithFrame:CGRectMake(43, 197, 160, 230)];
v3.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
[mainview addSubview: v1];
[v1 addSubview: v2];
[mainview addSubview: v3];

Swift:

let v1 = UIView(frame:CGRectMake(113, 111, 132, 194))
v1.backgroundColor = UIColor(red: 1, green: 0.4, blue: 1, alpha: 1)
let v2 = UIView(frame:CGRectMake(41, 56, 132, 194))
v2.backgroundColor = UIColor(red: 0.5, green: 1, blue: 0, alpha: 1)
let v3 = UIView(frame:CGRectMake(43, 197, 160, 230))
v3.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
mainview.addSubview(v1)
v1.addSubview(v2)
mainview.addSubview(v3)

效果:

绘制图形的视图方式为_三角函数图象的平移变换

 

5. Bounds and Center(边框和中心)

CGRectInset函数,画出视图边框

例1: 画一个带有粗边框的视图

UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(113, 111, 132, 194)];
v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1];
UIView* v2 = [[UIView alloc] initWithFrame:CGRectInset(v1.bounds, 10, 10)];
v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1];
[mainview addSubview: v1];
[v1 addSubview: v2];

效果:

绘制图形的视图方式为_三角函数图象的平移变换

 

例2: 移动超视图(spuerview)的原点导致子视图(subview)位置发生变化

       (本例中子视图向左上移动)

UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(113, 111, 132, 194)];
v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1];
UIView* v2 = [[UIView alloc] initWithFrame:CGRectInset(v1.bounds, 10, 10)];
v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1];
[mainview addSubview: v1]
[v1 addSubview: v2];
CGRect r = v1.bounds;
r.origin.x += 10;
r.origin.y += 10;
v1.bounds = r;

效果:

绘制图形的视图方式为_三角函数图象的平移变换

 

6. Transform(变换)

旋转(rotation), 缩放(scaling), 平移(translation)

例1: 视图顺时针旋转45度角

UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(113, 111, 132, 194)];
v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1];
UIView* v2 = [[UIView alloc] initWithFrame:CGRectInset(v1.bounds, 10, 10)];
v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1];
[mainview addSubview: v1];
[v1 addSubview: v2];
v1.transform = CGAffineTransformMakeRotation(45 * M_PI/180.0);

效果:
绘制图形的视图方式为_三角函数图象的平移变换

 

 

 

例2: 缩放变换

v1.transform = CGAffineTransformMakeScale(1.8, 1);

效果:
绘制图形的视图方式为_三角函数图象的平移变换

 

例3: 子视图先平移后旋转

UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(20, 111, 132, 194)];
v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1];
UIView* v2 = [[UIView alloc] initWithFrame:v1.bounds];
v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1];
[mainview addSubview: v1];
[v1 addSubview: v2];
v2.transform = CGAffineTransformMakeTranslation(100, 0);
v2.transform = CGAffineTransformRotate(v2.transform, 45 * M_PI/180.0);

效果:
绘制图形的视图方式为_三角函数图象的平移变换

 

例4: 子视图先旋转后平移

v2.transform = CGAffineTransformMakeRotation(45 * M_PI/180.0);
v2.transform = CGAffineTransformTranslate(v2.transform, 100, 0);

效果:

绘制图形的视图方式为_三角函数图象的平移变换

 

 

 例5: 旋转平移后再反转(删除旋转)

CGAffineTransformConcat – 合并两个变换动作

CGAffineTransform r = CGAffineTransformMakeRotation(45 * M_PI/180.0);
CGAffineTransform t = CGAffineTransformMakeTranslation(100, 0);
v2.transform = CGAffineTransformConcat(t,r);
v2.transform =
CGAffineTransformConcat(CGAffineTransformInvert(r), v2.transform);

效果:
绘制图形的视图方式为_三角函数图象的平移变换

 

例6: 倾斜

v1.transform = CGAffineTransformMake(1, 0, -0.2, 1, 0, 0);

效果:
绘制图形的视图方式为_三角函数图象的平移变换

 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/107063.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 4个线程池_vc2010线程win32线程已退出

    4个线程池_vc2010线程win32线程已退出在windows中,系统提供了QueueUserWorkItem函数实现异步调用,这个函数相当于在线程池中建立多个用户工作项目,跟普通线程机制一样,线程池也有线程的同步等机制。 【函数原型】BOOLWINAPIQueueUserWorkItem(__inLPTHREAD_START_ROUTINEFunction,__inP…

  • OV7725寄存器配置_i2c总线通信距离

    OV7725寄存器配置_i2c总线通信距离OV7725寄存器配置(为了替换NT99141研究了很长一段时间)部分参考链接:OV7725电器特性和时序图:https://www.cnblogs.com/raymon-tec/p/5087088.htmlOV7725摄像头的彩色图像采集原理与液晶显示(有必要了解框图):https://blog.csdn.net/huzhoudaxia/article/details/75269392…

  • 【笔记】EFCore & SQLite 拼音汉字互换

    【笔记】EFCore & SQLite 拼音汉字互换1vs2019新建.netcoreconsole项目,NuGet添加包Microsoft.EntityFrameworkCore//efcoreMicrosoft.EntityFrameworkCore.Design//在nugetMicrosoft.EntityFrameworkCore.Tools//控制台中管理数据迁移Microsoft.EntityFrameworkCore.Sqlite//sqliteM.

  • 使用tcpdump抓包分析网络请求_抓包报文分析

    使用tcpdump抓包分析网络请求_抓包报文分析tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具。tcpdump凭借强大的功能和灵活的截取策略,使其成为Linux系统下用于网络分析和问题排查的首选工具。tcpdump提供了源代码,公开了接口,因此具备很强的可扩展性,对于网络维护和入侵者都是非常有用的工具。tcpdump存在于基本的Linux系统中,由于它需要将网络界面设置为混杂模式,普通用户不能正常执行,但具备root权限的用户可以直接执行它来获取网络上的信息。因此系统中存在网络分析工具主要不是对本机安全的威胁,而是对

    2022年10月14日
  • UML活动图

    UML活动图面向对象的软件开发方法的第一步:业务建模<–使用活动图转载:https://www.cnblogs.com/xiaolongbao-lzh/p/4591953.html活动图概述•活动图和交互图是UML中对系统动态方面建模的两种主要形式•交互图强调的是对象到对象的控制流,而活动图则强调的是从活动到活动的控制流•活动图是一种表述过程基理、业务过程以及工作流的技术。它可以用…

  • plsql 连接oracle数据库详细配置「建议收藏」

    plsql 连接oracle数据库详细配置「建议收藏」第一次用这种方式连接oracle数据库,自己百度搞了快两个小时才弄好,百度的资源也不靠谱,看了好多都不完整,搞完了报各种错误,各种连不上数据库,自己整理下资料,希望给其他的同行予以借鉴,不能保证每个人都能操作成功!毕竟有时真的得看人品了,呵呵!第一步:先安装plsql客户端,plsql客户端是必须的,我的是同事给的plsql(英文版客户端)安装很简单(下一步下一步…….)就不做说明!

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号