uibezierpath

iOS学习日记(十六)视图与视图层次结构

若如初见. 提交于 2019-11-28 19:50:35
本节,学习视图与视图层次结构的概念,并编写一个Hypnosister应用。应用只有一个界面,绘制了一系列同心圆。 (1)创建项目 创建a single + class 如下 由于xcode8不支持空项目,所以要创建single 然后进行修改。 参考如下 https://blog.csdn.net/MR_ROG/article/details/41719985 (2)编辑AppDelegate.m文件。 UIView子类模板自动生成两个方法,第一个是initWithFrame: 这个方法是UIView的指定初始化方法,带一个CGRect 结构类型的参数。 视图的frame 属性保存的是 视图的大小和相对于父视图的位置。 CGRect结构包含另外两个结构:origin(是CGPoint结构 包含x 和y 两个float类型成员)和size(CGSize结构,包含两个float成员:width和height)。 打开AppDelegate.m 找到application:didFinishLaunchchingWithOptions:方法 在创建UIWindow之后创建一个CGRect结构,使用他创建一个BNRHypnosister对象,设置背景为红色,最后加入UIWindow对象,使其成为子窗口 - (BOOL)application:(UIApplication *

Draw gradient along a curved UIBezierPath

一笑奈何 提交于 2019-11-28 19:12:10
问题 In an app, I draw a curved UIBezierPath an an MKOverlayPathView class to show flight routes. This is the code I am using: - (UIBezierPath *)pathForOverlayForMapRect:(MKMapRect)mapRect { ... bla bla bla ... UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:s]; [path addQuadCurveToPoint:e controlPoint:cp1]; [path addLineToPoint:e2]; [path addQuadCurveToPoint:s2 controlPoint:cp2]; [path closePath]; return path; } - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale

IOS : Animate transformation from a line to a bezier curve

南楼画角 提交于 2019-11-28 16:35:24
I would like to animate a straight line curving into a bezier curve (from "_" to "n"), is there a library somewhere that can help me to do it ? I know how to draw a Bezier curve with UIBezierPath, I could redraw rapidly and progressively do the transformation, but if something already does that it would be cool :-) I might do something with a CADisplayLink . For example, you could do this in your view controller using a CAShapeLayer , e.g.: #import "ViewController.h" #import <QuartzCore/QuartzCore.h> @interface ViewController () @property (nonatomic) CFTimeInterval firstTimestamp; @property

Apply gradient color to arc created with UIBezierPath

依然范特西╮ 提交于 2019-11-28 16:00:47
I want to create a progress bar that has the form of an arc. The color of the progress bar has to change according to the values. I created an arc using UIBezierPath bezierPathWithArcCenter . I used the following code: - (void)viewDidLoad { [super viewDidLoad]; int radius = 100; CAShapeLayer *arc = [CAShapeLayer layer]; arc.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 50) radius:radius startAngle:60.0 endAngle:0.0 clockwise:YES].CGPath; arc.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, CGRectGetMidY(self.view.frame)-radius); arc.fillColor = [UIColor clearColor]

Multitouch tracking issue

徘徊边缘 提交于 2019-11-28 14:01:15
I am working with multitouch while writing, So basically what I am doing is, I am writing with hand support, because typically, its how user rights, I followed this link How to ignore certain UITouch Points in multitouch sequence So, what I am doing is , I am tracking a touch Object in touchesBegan and using that only in touchesMoved.Everything works fine, but some times while writing, I get this line In the above image, you can see the thick line which suddenly comes while writing with my hand touched on the screen Here is the code -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *

Calculate controlPoints while drawing in iOS

旧街凉风 提交于 2019-11-28 12:49:40
I am working on a drawing app, where user can draw/write with his finger or stylus. For this I have referred code from https://github.com/yusenhan/Smooth-Line-View , in my application. The problem which I am facing is that, the writing sometimes when you write very closely is not very smooth. So I think, I am making some mistake in getting the control point. Below is my code //Find the midpoint CGPoint midPoint(CGPoint p1, CGPoint p2) { return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5); } #pragma mark Gesture handle -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

Detecting tap inside a bezier path

冷暖自知 提交于 2019-11-28 12:04:21
I have a UIView which is added as a subview to my view controller. I have drawn a bezier path on that view. My drawRect implementation is below - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); UIBezierPath *bpath = [UIBezierPath bezierPath]; [bpath moveToPoint:CGPointMake(50, 50)]; [bpath addLineToPoint:CGPointMake(100, 50)]; [bpath addLineToPoint:CGPointMake(100, 100)]; [bpath addLineToPoint:CGPointMake(50, 100)]; [bpath closePath]; CGContextAddPath(context, bpath.CGPath); CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor);

UIBezierPath Subclass Initializer

北慕城南 提交于 2019-11-28 11:41:01
I'm trying to create a subclass of UIBezierPath to add some properties that are useful to me. class MyUIBezierPath : UIBezierPath { var selectedForLazo : Bool! = false override init(){ super.init() } /* Compile Error: Must call a designated initializer of the superclass 'UIBezierPath' */ init(rect: CGRect){ super.init(rect: rect) } /* Compile Error: Must call a designated initializer of the superclass 'UIBezierPath' */ init(roundedRect: CGRect, cornerRadius: CGFloat) { super.init(roundedRect: roundedRect, cornerRadius: cornerRadius) } required init(coder aDecoder: NSCoder) { fatalError("init

Draw a line with UIBezierPath

强颜欢笑 提交于 2019-11-28 05:47:29
First time using BezierPaths, wondering how this function is actually supposed to be implemented. Currently the bezier path moves within the frame of the image, as opposed to drawing on screen. Is there a better way to do it? func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) { var maxWidth = abs(start.x - end.x) var maxHeight = abs(start.y - end.y) var contextSize : CGSize! if maxWidth == 0 { contextSize = CGSize(width: 1, height: maxHeight) }else { contextSize = CGSize(width: maxWidth, height: 1) } //design the path

Detect if drawing a path is a circle/rectangle in xcode

做~自己de王妃 提交于 2019-11-28 05:10:42
问题 I want to implement a auto complete feature for a drawing app. Once a free hand object is drawn, I want to detect the type of object (circle/rectangle/triangle) and based on the result would want to plot a corresponding object. I have read up a bit about OpenCV but then I would need to convert the user drawing into an image at real time. I am recording the number of points plotted/traced by the touch and also generate a UIBeizerPath of the corresponding path. How do I go about to detecting