首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

iOS实践:通过核心动画完成过山车1. 思路和所用到的内容2. 辅助元素的创建(背景颜色、草坪、大地、小树、云彩)3. 雪山的实现4. 轨道的实现

呼哧,终于今天到了最后一篇啦,也是醉了,弄了两三个月。从最开始计划只写三篇就好了,结果自己没把握好,一点点加成了今天这个样子。因为增加的内容太多,也差点变成太监文,不过好在没有放弃自己。所以各位行行好,要是看上去觉得还不错,就点个赞,打赏小的点儿。这玩意儿写的我是头发乱发,两眼通红。哇哇哇哇~ 接下来要写啥,确实还没想好。现在的感觉就是胸口的一块大石头没有了,要去尽情的嗨皮!!!! 之前在一个网站上看到了一个HTML5/SVG实现的过山车动画,点这里看网页版。 觉得很棒,想想咱们iOS也完全可以实现,正好还

05

IOS 图文新闻文章样式

//在实现图文混排的功能之前,首先往项目中添加一个继承自UIView 父类的子类CTImageView.swift。使用该类的draw方法,并在该方法中使 用Core Text框架渲染富文本, 1 let picWidth = CGFloat(200.0) 2 let picHeight = CGFloat(133.0) 3 UIColor.brown.setFill() 4 UIRectFill(rect) 5 var ctRunCallback = CTRunDelegateCallbacks(version: kCTRunDelegateVersion1, dealloc: { (refCon) -> Void in 6 }, getAscent:{ ( refCon) -> CGFloat in 7 return picHeight 8 }, getDescent:{ (refCon) -> CGFloat in 9 return 0 10 }) { (refCon) -> CGFloat in 11 return picWidth 12 } 13 var picture = “coffee “ 14 let ctRunDelegate = CTRunDelegateCreate(&ctRunCallback, &picture) 15 let placeHolder = NSMutableAttributedString(string:” “) 16 placeHolder.addAttribute(kCTRunDelegateAttributeName as String, value:ctRunDelegate!, range: NSMakeRange(0, 1)) 17 placeHolder.addAttribute(“pictureName”, value: picture, range:NSMakeRange(0, 1)) 18 let article = “咖啡(coffee)是采用经过烘焙的咖啡豆所 制作出来\n\n的饮料,通常为热饮,但也有 作为冷饮的冰咖啡。 咖啡是人类社会流行范围最为广泛的饮料之一,也是重要经济作 物。在繁忙的工作生活 之余,我们可以去尝试做自己的咖啡。” 19 let attributedStr = NSMutableAttributedString(string: article) 20 attributedStr.insert(placeHolder, at:27) 21 attributedStr.addAttribute(kCTUnderlineStyleAttributeName as String, value:NSNumber(value:1), range: NSRange(location:0, length:attributedStr.length)) 22 let framesetter = CTFramesetterCreateWithAttributedString(attributedStr) 23 let path = UIBezierPath(rect:rect) 24 let ctFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attributedStr.length), path.cgPath, nil) 25 26 let crtContext = UIGraphicsGetCurrentContext() 27 crtContext!.textMatrix = CGAffineTransform.identity 28 crtContext?.scaleBy(x:1.0, y:-1.0) 29 crtContext?.translateBy(x:0, y: self.bounds.size.height * -1) 30 CTFrameDraw(ctFrame, crtContext!) 31 let ctLines = CTFrameGetLines(ctFrame) as NSArray 32 var originsOfLines = CGPoint 33 for _ in 0..<ctLines.count{ 34 originsOfLines.append(CGPoint.zero) 35 } 36 let range:CFRange = CFRangeMake(0, 0) 37 CTFrameGetLineOrigins(ctFrame, range, &originsOfLines) 38 for i in 0..<ctLines.co

02
领券