With an understanding ofC structures, and thedefinitions of CGRect, CGSize and CGPointbehind us, let’s look at a handful of functions for working with these structures.
CGRectMake and NSStringFromCGRect
With CGRectMake we can create a new CGRect structure. The rectangles below have differing starting points, however, each have a width and height of 100. The function NSStringFromCGRect returns a string object that defines the rectangle passed in as a parameter:
Note: The output of all examples are shown in the image at the bottom of this post.
CGRectIntersect
To determine if two rectangles intersect, you can write code as follows:
CGRectInset
If you need to create a rectangle that is either larger or smaller than an existing rectangle, centered on the same point, try CGRectInset:
CGRectFromString
A little more uncommon, is creating rectangles from a string, however, if the need arises:
Functions for CGSize and CGPoint
As you would expect, there are similar functions to those above for working with CGSize and CGPoint:
- CGSizeMake
- CGSizeEqualToSize
- CGPointMake
- CGPointEqualToPoint
http://iphonedevelopertips.com/c/cgrect-cgsize-and-cgpoint-functions.html
分享到:
相关推荐
再来看数据类型的比较,包括CGRect、CGSize、CGPoint结构体以及NSDate对象。在iOS开发中,比较这些数据类型的实例是否相等,通常会使用特定的函数。比如,使用CGRectEqualToRect函数来比较两个CGRect结构体是否相等...
其中,`origin`是一个`CGPoint`,表示矩形左上角的坐标,`size`是一个`CGSize`,表示矩形的宽度和高度。在进行视图布局时,`CGRect`常用来设置或获取视图的frame,即视图在父视图中的位置和大小。 接下来,我们看看...
通过上述内容的学习,我们了解到在iPhone开发过程中,`UIScreen`、`CGRect`、`CGPoint`和`CGSize`这几个类或结构体的重要性。它们不仅能够帮助我们更好地理解设备的基本信息,还能够指导我们在开发过程中做出正确的...
SwiftCGRectExtensions 是 CGRect, CGPoint 和 CGSize 简便函数的集合,使用 Swift 编写,支持 iOS 和 OS X。 SwiftCGRectExtensions 目标是为普遍使用的 rect 操作提供清晰的函数。 特性 Operators for adding, ...
本笔记主要关注的是iOS开发中的基础概念,特别是与几何图形处理相关的部分,如CGRect、CGPoint、CGSize以及它们在不同场景下的应用。以下是对这些概念的详细解释: 1. CGRect: CGRect是苹果的Core Graphics框架中...
float,double,NSInteger,CGFloat,BOOL,NSString,NSMutableString,NSNumber,NSArray,NSMutableArray,NSDictionary,NSMutableDictionary,NSData,NSMutableData,UIImage,NSDate,NSURL,NSRange,CGRect,CGSize,CGPoint,...
在iOS开发中,使用的主要数据结构包括CGPoint、CGSize和CGRect。CGPoint用来表示点的位置信息,它包含x和y两个属性,分别表示点在x轴和y轴上的坐标。CGSize用来表示一个尺寸,包含width和height两个属性,分别表示...
logo.draw(in: CGRect(origin: CGPoint.zero, size: CGSize(width: logoSize, height: logoSize))) context.restoreGState() let newImage = UIGraphicsGetImageFromCurrentImageContext() ...
CGPoint cgPoint = CGPointMake(30.0, 40.0); // 创建一个位于(30.0, 40.0)的点 ``` 3. NSSize / CGSize `NSSize`用于表示二维尺寸,包含宽度`width`和高度`height`两个浮点数。在Core Graphics中,对应的结构体是`...
- 创建 `CGPoint` 和 `CGSize` 可以使用 `CGPointMake` 和 `CGSizeMake` 方法。 ```objective-c CGPoint point = CGPointMake(x, y); CGSize size = CGSizeMake(width, height); ``` ##### 4. **视图属性设置...
CGPoint、CGRect和CGSize结构体用于定义位置和大小。例如,UIView的frame属性包含了它的位置(CGPoint)和大小(CGSize),而contentOffset则表示滚动时视图相对于其内容的位置。 构建TableView涉及几个关键对象: ...
#### 三、CGPoint和CGSize - **创建一个CGPoint**: ```objective-c CGPoint point = CGPointMake(x, y); ``` - **创建一个CGSize**: ```objective-c CGSize size = CGSizeMake(width, height); ``` 这些...
- `CGPointIsInRange(CGPoint point, CGRect range)`:检查一个点是否位于指定矩形范围内。 - `CGPointRelativeToCenter(CGPoint point, CGPoint center)`:获取点相对于中心点的位置,返回一个新的坐标。 - `...
FTPopOverMenu, 简单易用的弹出Menu,支持UIButton,UIBarButtonItem,以及任何UIView或CGRect。Github demo地址:https://github.com/liufengting/FTPopOverMenu
let path = UIBezierPath(ovalIn: CGRect(center: point, size: CGSize(width: radius * 2, height: radius * 2))) if i == currentPage { path.fill(with: UIColor.red) // 实心,可根据需求更改颜色 } else ...
4. `- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity`:这个方法用于计算滚动到某一位置时,内容区域应该偏移的位置,对于瀑布流...
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint { // 计算滚动到目标偏移量时的真实内容偏移量 return ...
在iOS中,处理位置和尺寸的还有CGPoint和CGSize结构体,分别表示点和尺寸。例如: ```swift CGPoint aPoint = CGPointMake(10, 20); CGSize aSize = CGSizeMake(300, 400); ``` 透明度可以通过`setAlpha:`方法设置...
CGRect范围; BOOL hasLeftEyePosition; CGPoint leftEyePosition; CGPoint rightEyePosition; BOOL hasMouthPosition; CGPoint rightPosition; BOOL hasTrackingID; int trackingID; BOOL hasTrackingFrameCount; ...