iOS10 UI教程視圖的邊界與視圖的框架

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

iOS10 UI教程視圖的邊界與視圖的框架

iOS10 UI視圖的邊界

在視圖的幾何形狀中我們提到了視圖屬性中的一部分屬性可以將定義的視圖繪制在屏幕上。其中典型的3個屬性為邊界屬性、框架屬性以及中心位置屬性。

bounds表示的就是邊界屬性,它是一個CGRect屬性。它定義了該視圖本身內部的坐標系統中的位置(origin)和大小(size)。在大多數情況下bounds中的origin屬性為(x: 0, y: 0),size屬性為視圖的大小。在使用bounds時,我們不可以確定視圖是如何繪制在UI層次結構中的。

iOS10 UI視圖的框架

frame表示的就是框架屬性,定義了視圖圖如何放置層次結構中。frame是一個CGRect屬性,它類型與bounds屬性,但是frame的origin屬性決定了視圖如何放置它的父視圖中。

注意:bounds屬性和frame屬性類似,但有所不同,bounds指的是該視圖本身內部的坐標系統中的位置和大小。參照點是本身的坐標系統,即為絕對坐標,而frame指的是該視圖在設計界面坐標系統中的位置和大小。參照點是設計界面,即為相對坐標。

【示例1-4:Frame】以下我們將使用代碼說明frame和bounds的不同。具體的操作步驟如下:

(1)打開ViewController.swift文件,編寫代碼,實現在屏幕上顯示一個紅色的空白視圖,并且分別輸出bounds和frame的位置和大小。代碼如下:

import UIKitclass ViewController: UIViewController {override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.let point=CGPoint(x: 67.0, y: 217.0)let size=CGSize(width: 240.0, height: 128.0)let rect=CGRect(origin: point, size: size)let newView=UIView(frame: rect)self.view.addSubview(newView)newView.backgroundColor=UIColor.red//輸出bounds的位置print("bounds.origin.x:\(newView.bounds.origin.x)")print("bounds.origin.y:\(newView.bounds.origin.y)")//輸出bounds的大小print("bounds.size.width:\(newView.bounds.size.width)")print("bounds.size.height:\(newView.bounds.size.height)")//輸出frame的位置和大小print("frame.origin.x:\(newView.frame.origin.x)")print("frame.origin.y:\(newView.frame.origin.y)")print("frame.size.width:\(newView.frame.size.width)")print("frame.size.height:\(newView.frame.size.height)")}……}

此時運行程序,會看到如圖1.9所示的效果

圖1.9 ?運行效果 ? ? 圖1.10 ?運行效果

此時會在應用程序輸出窗口輸出如下內容:

//bounds的位置和大小bounds.origin.x:0.0bounds.origin.y:0.0bounds.size.width:240.0bounds.size.height:128.0//frame的位置和大小frame.origin.x:67.0frame.origin.y:217.0frame.size.width:240.0frame.size.height:128.0

注意:在以上這些情況中,frame和bounds的size是相同的,但是origin是不同的。

(2)修改vViewController.swift文件中的viewDidLoad()方法中的代碼,實現空白視圖的旋轉,旋轉后再分別輸出bounds和frame的位置和大小。代碼如下:

override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.let point=CGPoint(x: 67.0, y: 217.0)let size=CGSize(width: 240.0, height: 128.0)let rect=CGRect(origin: point, size: size)let newView=UIView(frame: rect)self.view.addSubview(newView)newView.backgroundColor=UIColor.rednewView.transform=CGAffineTransform(rotationAngle: 45)???????????????????????????????????????//旋轉print("bounds.origin.x:\(newView.bounds.origin.x)")……}

此時運行程序,會看到如圖1.10所示的效果。在應用程序輸出窗口輸出以下內容:

//bounds的位置和大小bounds.origin.x:0.0bounds.origin.y:0.0bounds.size.width:240.0bounds.size.height:128.0//frame的位置和大小frame.origin.x:69.5035357716888frame.origin.y:145.270969771571frame.size.width:234.992928456622frame.size.height:271.458060456858

注意:在旋轉視圖后,bounds的位置和大小和在沒有旋轉視圖之前是一樣的。frame發生了變化,為了容納旋轉后的視圖,尺寸會自動進行調整。

iOS10 UI教程視圖的邊界與視圖的框架

相關閱讀:iOS10 UI教程視圖的幾何形狀

轉載于:https://my.oschina.net/u/1585857/blog/792856

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542197.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542197.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542197.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Java System類runFinalization()方法及示例

系統類runFinalization()方法 (System class runFinalization() method) runFinalization() method is available in java.lang package. runFinalization()方法在java.lang包中可用。 runFinalization() method is used to run the finalize() methods of any object that are…

Linux中遠程文件的傳輸

1. scp命令 scp file userip:/dir 把自己主機的文件遠程復制到其他主機 scp userip:/file dir 把其他主機的文件遠程復制到當前主機 注意:要關閉接受端的防火墻 把主機的file遠程復制到IP為172.25.254.117的root用戶的Desktop 把IP為172.25.254.117的root用戶Deskt…

svn: Can't convert string from 'UTF-8' to native

詳見:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt227 svn 版本庫中有文件是以中文字符命名的,在 Linux 下 checkout 會報錯: svn: Cant convert string from UTF-8 to native encoding 然后 checkout 程序就退出了&#xff…

引入antd組件樣式_個人作品:一個技術棧koa2+ mysql+react + antd的個人博客

前言此項目是個人博客,有前端界面后臺管理系統;目的是當做react和node的練手項目,同時還可以了解到服務器nginx部署web站點以及備案和域名的基本操作流程。項目預覽地址https://www.lxsblog.cn?www.lxsblog.cnGitHub地址LinWeb/blog?github…

Java ObjectOutputStream writeLong()方法與示例

ObjectOutputStream類writeLong()方法 (ObjectOutputStream Class writeLong() method) writeLong() method is available in java.io package. writeLong()方法在java.io包中可用。 writeLong() method is used to write the given 8 bytes long value. writeLong()方法用于寫…

淺談Jfinal急速開發框架

2019獨角獸企業重金招聘Python工程師標準>>> 使用Jfinal一段時間了,記得當初14年吧,為了建立一個簡單的門戶網站,想找個輕量型的急速開發框架,然后搜到Jfinal,然后用了一段時間后,確實不錯, 現在吧,隨著時間的推移,作者對JFinal的版本迭代也是一直在努力,一直朝著優…

make 怎么降級_Ubuntu 中將 make 的版本降低

最新的 Ubuntu 版本使用的是 make 版本是 4.0.在編譯 Android4.4 源碼包時,由于 make 版本過高,命令提示行會提示編譯 Android4.4 源碼包需要 make 的版本為 3.81 或 3.82.build/core/main.mk:42: ****************************************************…

Java ObjectOutputStream writeChar()方法與示例

ObjectOutputStream類writeChar()方法 (ObjectOutputStream Class writeChar() method) writeChar() method is available in java.io package. writeChar()方法在java.io包中可用。 writeChar() method is used to write 2 bytes of a character value. writeChar()方法用于寫…

虛擬機的管理

我們采用虛擬機的原因是什么呢,很簡單就倆字: 節能 1. 管理虛擬機的命令: virt-manager開啟虛擬機管理器virsh list顯示正在運行的虛擬機virsh list --all查看所有虛擬機virsh start desktop打開虛擬機virsh shutdown desktop正常關閉虛擬機…

mybatis對java自定義注解的使用——入門篇

轉自;https://www.cnblogs.com/sonofelice/p/4980161.html 1. 最近在學習spring和ibatis框架。 以前在天貓實習時做過的一個小項目用到的mybatis,在其使用過程中,不加思索的用了比較原始的一種持久化方式: 在一個包中寫一個DAO的接…

Java BigDecimal toBigIntegerExact()方法(帶示例)

BigDecimal類的toBigIntegerExact()方法 (BigDecimal Class toBigIntegerExact() method) toBigIntegerExact() method is available in java.math package. toBigIntegerExact()方法在java.math包中可用。 toBigIntegerExact() method is used to convert this BigDecimal int…

Linux中的軟件管理

1. 使用已有的網絡安裝資源安裝軟件 cd /etc/yum.repos.d/ (移動到yum源指向的文件配置目錄下) vim westos.repo (新建文件,yum下后綴必須為.repo) 編輯這個文件里面寫 [redhat] (軟件倉庫名稱) namefirefox &#x…

楚留香ai人臉識別_戴口罩居然也能人臉識別?這些AI黑科技真的藏不住了.........

當人工智能遇見影像技術,將會釋放出多少意想不到的巨大能量?「喔圖知圖實驗室」瞄準當下的影像痛點,持續發力升級AI黑科技,帶來兩大必殺技——人臉識別再度升級、AI智能旋轉校正。戴口罩也能識別——人臉識別升級戴口罩人臉識別如…

android--------Popupwindow的使用

2019獨角獸企業重金招聘Python工程師標準>>> PopupWindow在Android.widget包下,項目中經常會使用到PopupWindow做菜單選項, PopupWindow這個類用來實現一個彈出框,可以使用任意布局的View作為其內容,這個彈出框是懸浮…

使用JavaScript中的示例的escape()函數

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string. 在通過網絡傳輸數據或有時將數據保存到數據庫…

安裝虛擬機的腳本

1. 先安裝生成自動安裝腳本的工具 yum install system-config-kickstart -y 2. 打開這個軟件 system-config-kickstart 基本設置:更改時區為上海,設置root用戶密碼 2)設置安裝方法為網絡安裝,將共享的鏡像文件地址正確填寫 3&…

小小小游戲

寫著玩 FlappyBird 視頻:https://pan.baidu.com/s/1sljIR5z 游戲:https://pan.baidu.com/s/1ge8j7Ej 項目:https://pan.baidu.com/s/1eSysxpw Breakout 視頻:https://pan.baidu.com/s/1gfhv4hd 項目:https://pan.baidu.com/s/1hs8xPly QBert 視頻:https://pan.baidu.com/s/1s…

go在方法中修改結構體的值_[Go]結構體及其方法

結構體類型可以包含若干字段,每個字段通常都需要有確切的名字和類型。也可以不包含任何字段,這樣并不是沒有意義的,因為還可以為這些類型關聯上一些方法,這里可以把方法看作事函數的特殊版本。函數事獨立的程序實體,可…

to_number用法示例_Number()函數以及JavaScript中的示例

to_number用法示例Number()函數 (Number() function) Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert the object in a number – it returns "NaN". (Rea…

系統延時任務及定時任務

1. 系統延時任務&#xff1a; at相關命令 at time 設定任務執行時間at> rm -fr /mnt/* 任務動作at> <EOT> <<ctrld 執行任務at的命令&#xff1a; -l ##查看任務列表-c …