xcode 如何在iphone上画一个虚线矩形选框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1427516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:50:24  来源:igfitidea点击:

How to draw a dotted rectangle marquee on iphone?

objective-ciphonexcodecore-graphics

提问by Rahul Vyas

How to draw rectangle something like this in iphone sdk using core graphics

如何使用核心图形在iphone sdk中绘制这样的矩形

Screen Shot of the Crop Tool

裁剪工具的屏幕截图

回答by Dave DeLong

That's five rectangles.

那是五个矩形。

You construct a CGPath for the dotted line rectangle, stroke it, and then construct the four little CGPaths for the handles and stroke those.

您为虚线矩形构造一个 CGPath,对其进行描边,然后为手柄构造四个小 CGPath 并描边它们。

回答by dlamblin

Specifically if you look at the actual iPhone reference documentation for CGPathYou'll find a section about CGPathAddRect. After which you'll probably find the section of the 2D guide on Painting a Pathuseful.

具体来说,如果您查看实际的 iPhone 参考文档,CGPath您将找到有关 CGPathAddRect 的部分。之后,您可能会发现有关绘制路径的 2D 指南部分很有用。

CGPathAddRect

CGPathAddRect

Appends a rectangle to a mutable graphics path.

将矩形附加到可变图形路径。

void CGPathAddRect (
   CGMutablePathRef path,
   const CGAffineTransform *m,
   CGRect rect
);

Parameters
path
The mutable path to change.

参数
path
要更改的可变路径。

m
A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Quartz applies the transformation to the rectangle before adding it to the path.

m
指向仿射变换矩阵的指针,如果不需要变换,则为 NULL。如果指定,Quartz 在将矩形添加到路径之前将其应用到矩形。

rect
The rectangle to add.

rect
要添加的矩形。

Discussion
This is a convenience function that adds a rectangle to a path, using the following sequence of operations:

讨论
这是一个向路径添加矩形的便捷函数,使用以下操作序列:

// start at origin
CGPathMoveToPoint (path, m, CGRectGetMinX(rect), CGRectGetMinY(rect));

// add bottom edge
CGPathAddLineToPoint (path, m, CGRectGetMaxX(rect), CGRectGetMinY(rect));

// add right edge
CGPathAddLineToPoint (path, m, CGRectGetMaxX(rect), CGRectGetMaxY(rect);

// add top edge
CGPathAddLineToPoint (path, m, CGRectGetMinX(rect), CGRectGetMaxY(rect));

// add left edge and close
CGPathCloseSubpath (path);

Availability
Available in iPhone OS 2.0 and later.

可用性
在 iPhone OS 2.0 及更高版本中可用。

Declared In
CGPath.h


CGPath.h 中声明

回答by NSResponder

I would recommend dispensing with the handles. They make sense when you're using a mouse; with a touch screen, not so much.

我建议免除手柄。当您使用鼠标时,它们是有意义的;带触摸屏,没那么多。