IOS学习随笔三

 
IOS storyboard做界面跳转设计页面:
self.dismissViewControllerAnimated(true, completion: nil ) ios8已经替换掉了老得方法定义  使用两个参数的dismissViewControllerAnimated
NIB做界面设计:
self.presentViewController(MyViewController(nibName: "MyViewController", bundle: nil), animated: true, completion: nil)
MyViewConroller是自己搭建的UIViewController子类,同时生成了nib文件
 iOS绘图API
1绘图的第一步是声明一个
 var context = UIGraphicsGetCurrentContext() ;//用来保存当前的绘图内容
2可以通过 CGContextAddLineToPoint 画直线  ,线需要先确定一个点----CGContextMoveToPoint
通过 CGContextAddRect 画矩形
通过 CGContextAddArc画扇形-----》和圆
通过  CGContextAddEllipseInRect来画一个矩形的内接圆———椭圆和圆
通过 CGContextDrawImage 来把画图片呈现到视图上,
这里需要先通过CGContextScaleCTM//首先放入的图是倒过来的,图片和试图的编码方式导致y是-1
3CGcontextSet 等方法来设置这些图像的属性比如颜色和线框等
4显示图形,通过CGContextStrokePath(context)来显示线 ,通过CGContextFillPath(context)来显示填充
绘图中
//为了不在绘制图的时候影响其他绘图,先保存状态,然后再恢复
        CGContextSaveGState(context)
        CGContextRestoreGState(context)
2-13画板实例
首先重载两个方法
touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
//确定触摸的起始点
var p = touches.anyObject()?.locationInView(self)
CGPathMoveToPoint(path, nil, p!.x , p!.y)
}
touchesMoved(touches: NSSet, withEvent event: UIEvent)
{ var p = touches.anyObject()?.locationInView(self)
 CGPathAddLineToPoint(path, nil, p!.x, p!.y)  
   setNeedsDisplay();//显示图形
 
}
 
 
 
 

转载于:https://www.cnblogs.com/KyleRuan/p/4296081.html

猜你喜欢

转载自blog.csdn.net/weixin_34288121/article/details/93435600