<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jmovxia on Medium]]></title>
        <description><![CDATA[Stories by Jmovxia on Medium]]></description>
        <link>https://medium.com/@jmovxia?source=rss-5855d65cb36b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ec4DY4p0hWSPr8hg.jpg</url>
            <title>Stories by Jmovxia on Medium</title>
            <link>https://medium.com/@jmovxia?source=rss-5855d65cb36b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 09:05:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jmovxia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[使用AVPlayer自定义支持全屏的播放器（五）-Swift重构版本]]></title>
            <link>https://jmovxia.medium.com/%E4%BD%BF%E7%94%A8avplayer%E8%87%AA%E5%AE%9A%E4%B9%89%E6%94%AF%E6%8C%81%E5%85%A8%E5%B1%8F%E7%9A%84%E6%92%AD%E6%94%BE%E5%99%A8-%E4%BA%94-swift%E9%87%8D%E6%9E%84%E7%89%88%E6%9C%AC-282ce91f2244?source=rss-5855d65cb36b------2</link>
            <guid isPermaLink="false">https://medium.com/p/282ce91f2244</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[avplayer]]></category>
            <dc:creator><![CDATA[Jmovxia]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 02:29:41 GMT</pubDate>
            <atom:updated>2021-12-29T02:30:43.539Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lXn-ejDCjJBdYwqoNNxHzg.png" /></figure><p>很早之前开源了一个简单的视频播放器，由于年久失修，效果惨目忍睹，最近特意花时间对其进行了深度重构。旧版本后期不再维护，新版本使用 Swift实现，后续会增加更多功能。不想看文字的请自行下载代码------&gt;&gt;&gt; <a href="https://github.com/JmoVxia/CLPlayer">CLPlayer</a></p><ol><li><strong>新版本使用</strong><strong>Swift，旧版本使用</strong><strong>Objective-C</strong></li><li><strong>新版本采用自定义转场实现全屏，旧版本使用旋转屏幕</strong></li><li><strong>新版本不需要手动销毁播放器</strong></li><li><strong>新版本修复了老版本遗留bug</strong></li><li><strong>新版本降低了代码耦合性</strong></li><li><strong>新版本增加了倍数播放，切换填充模式</strong></li><li><strong>新版本提供更丰富的API</strong></li><li><strong>新版本适配了iPhone X</strong></li><li><strong>新版本移除了状态栏相关配置</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/0*pEt2MKP1uioZ0Ofy" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/0*A3q4RNkcUr_jOhoB" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/0*us3gBpm5vxOOhLrQ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/0*_LtDPuEMi6Q-xIfk" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/0*kHMDCvCeomxgwCW5" /></figure><p><strong>项目必须支持全屏，建议将屏幕支持方向交由当前显示的控制器自行管理。</strong></p><h4>项目支持全屏方案</h4><h4>1.先勾选支持方向，只保留portrait，保证APP启动不会横屏</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*PE7CdzwvQzLfCYC3" /></figure><h4>2.AppDelegate中重写func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -&gt; UIInterfaceOrientationMask {}方法</h4><pre>func application(_: UIApplication, supportedInterfaceOrientationsFor _: UIWindow?) -&gt; UIInterfaceOrientationMask {<br>    return .allButUpsideDown<br>}</pre><h4>3.在父类中重写屏幕控制相关方法</h4><p>UITabBarController</p><pre>override var shouldAutorotate: Bool {<br>    if let navigationController = selectedViewController as? UINavigationController {<br>        return navigationController.topViewController?.shouldAutorotate ?? false<br>    } else {<br>        return selectedViewController?.shouldAutorotate ?? false<br>    }<br>}</pre><pre>override var supportedInterfaceOrientations: UIInterfaceOrientationMask {<br>    if let navigationController = selectedViewController as? UINavigationController {<br>        return navigationController.topViewController?.supportedInterfaceOrientations ?? .portrait<br>    } else {<br>        return selectedViewController?.supportedInterfaceOrientations ?? .portrait<br>    }<br>}</pre><pre>override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {<br>    if let navigationController = selectedViewController as? UINavigationController {<br>        return navigationController.topViewController?.preferredInterfaceOrientationForPresentation ?? .portrait<br>    } else {<br>        return selectedViewController?.preferredInterfaceOrientationForPresentation ?? .portrait<br>    }<br>}</pre><p>UINavigationController</p><pre>override var shouldAutorotate: Bool {<br>    return topViewController?.shouldAutorotate ?? false<br>}</pre><pre>override var supportedInterfaceOrientations: UIInterfaceOrientationMask {<br>    return topViewController?.supportedInterfaceOrientations ?? .portrait<br>}</pre><pre>override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {<br>    return topViewController?.preferredInterfaceOrientationForPresentation ?? .portrait<br>}</pre><p>UIViewController</p><pre>override var shouldAutorotate: Bool {<br>    return true<br>}</pre><pre>override var supportedInterfaceOrientations: UIInterfaceOrientationMask {<br>    return .portrait<br>}</pre><pre>override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {<br>    return .portrait<br>}</pre><h4>4.部分页面需要支持多方向</h4><p>在对应控制器中重写以下方法</p><pre>override var shouldAutorotate: Bool {<br>    return true<br>    <br>}<br>override var supportedInterfaceOrientations:  UIInterfaceOrientationMask {<br>    return .allButUpsideDown<br>}</pre><h4>基础配置</h4><pre>public struct CLPlayerConfigure {<br>    /// 顶部工具条隐藏风格<br>    public enum CLPlayerTopBarHiddenStyle {<br>        /// 小屏和全屏都不隐藏<br>        case never<br>        /// 小屏和全屏都隐藏<br>        case always<br>        /// 小屏隐藏，全屏不隐藏<br>        case onlySmall<br>    }<br>    /// 自动旋转<br>    public var isAutoRotate = true<br>    /// 手势控制<br>    public var isGestureInteractionEnabled = true<br>    /// 是否显示更多面板<br>    public var isShowMorePanel = true<br>    /// 顶部工具条隐藏风格<br>    public var topBarHiddenStyle: CLPlayerTopBarHiddenStyle = .<br>    /// 工具条自动消失时间<br>    public var autoFadeOut: TimeInterval = 5<br>    /// 默认拉伸方式<br>    public var videoGravity: AVLayerVideoGravity = .resizeAspectFill<br>    /// 顶部工具条背景颜色<br>    public var topToobarBackgroundColor: UIColor = .black.withAlphaComponent(0.6)<br>    /// 底部工具条背景颜色<br>    public var bottomToolbarBackgroundColor: UIColor = .black.withAlphaComponent(0.6)<br>    /// 进度条背景颜色<br>    public var progressBackgroundColor: UIColor = .white.withAlphaComponent(0.35)<br>    /// 缓冲条缓冲进度颜色<br>    public var progressBufferColor: UIColor = .white.withAlphaComponent(0.5)<br>    /// 进度条播放完成颜色<br>    public var progressFinishedColor: UIColor = .white<br>    /// 转子背景颜色<br>    public var loadingBackgroundColor: UIColor = .white<br>    /// 返回按钮图片<br>    public var backImage: UIImage?<br>    /// 更多按钮图片<br>    public var moreImage: UIImage?<br>    /// 播放按钮图片<br>    public var playImage: UIImage?<br>    /// 暂停按钮图片<br>    public var pauseImage: UIImage?<br>    /// 进度滑块图片<br>    public var sliderImage: UIImage?<br>    /// 最大化按钮图片<br>    public var maxImage: UIImage?<br>    /// 最小化按钮图片<br>    public var minImage: UIImage?<br>    /// 封面图片<br>    public var maskImage: UIImage?<br>}</pre><p>本次重构为 Swift第一版，后续会持续更新，定制化开发请自行参考 <a href="https://github.com/JmoVxia/CLPlayer">CLPlayer</a> 修改 ， 如果喜欢，欢迎star。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=282ce91f2244" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS开发之转盘菜单-Swift]]></title>
            <link>https://jmovxia.medium.com/ios%E5%BC%80%E5%8F%91%E4%B9%8B%E8%BD%AC%E7%9B%98%E8%8F%9C%E5%8D%95-swift-f08e445e4b08?source=rss-5855d65cb36b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f08e445e4b08</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jmovxia]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 03:41:53 GMT</pubDate>
            <atom:updated>2021-05-20T07:19:05.695Z</atom:updated>
            <content:encoded><![CDATA[<p>使用Swift实现的转盘菜单，主要用到 UIBezierPath、 CALayer遮罩绘制扇形 UIView， CATransform3DMakeRotation实现旋转动画。代码设计使用默认 configureCallback回调方便创建和设置基本属性，参考 UITableView代理和数据源模式，支持 AutoLayout和 Frame 。</p><h3>效果图</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/0*Q5c3tWuD3uqyYXdp" /></figure><h3>1.遮罩绘制扇形View</h3><p>计算扇形曲线位置，通过 CALayer的 mask属性绘制出扇形 UIView 核心代码</p><pre>func setMaskLayer(_ startAngle: CGFloat, endAngle: CGFloat) {<br>    let center = CGPoint(x: bounds.width * 0.5, y: bounds.height * 0.5)<br>    let layer = CAShapeLayer()<br>    path.addArc(withCenter: center, radius: bounds.width * 0.5, startAngle: startAngle, endAngle: endAngle, clockwise: true)<br>    path.addLine(to: center)<br>    layer.path = path.cgPath<br>    layer.rasterizationScale = UIScreen.main.scale<br>    layer.shouldRasterize = true<br>    self.layer.mask = layer<br>}</pre><h3>2.中间镂空</h3><pre>func createHole(in view : UIView, radius: CGFloat)   {<br>    let path = CGMutablePath()<br>    path.addArc(center: view.center, radius: radius, startAngle: 0.0, endAngle: 2.0 * .pi, clockwise: true)<br>    path.addRect(CGRect(origin: .zero, size: view.bounds.size))<br>    let maskLayer = CAShapeLayer()<br>    maskLayer.path = path<br>    maskLayer.fillRule = .evenOdd<br>    view.layer.mask = maskLayer<br>    view.clipsToBounds = true<br>}</pre><h3>3.旋转动画</h3><p>添加 UIPanGestureRecognizer、 UITapGestureRecognizer手势，根据手势位置使用 atan2函数计算旋转角度，然后用 CATransform3DMakeRotation围绕 Z 轴旋转做动画 核心代码</p><pre>func handlePanGesture(_ sender: UIPanGestureRecognizer) {<br>    let location = sender.location(in: self)<br>    switch sender.state {<br>    case .began:<br>        startPoint = location<br>    case .changed:<br>        let radian1 = -atan2(startPoint.x - menuLayerView.center.x, startPoint.y - menuLayerView.center.y)<br>        let radian2 = -atan2(location.x - menuLayerView.center.x, location.y - menuLayerView.center.y)<br>        menuLayerView.transform = menuLayerView.transform.rotated(by: radian2 - radian1)<br>        startPoint = location<br>    default:<br>        let angle = 2 * CGFloat(Double.pi) / CGFloat(cells.count)<br>        var menuViewAngle = atan2(menuLayerView.transform.b, menuLayerView.transform.a)<br>        if menuViewAngle &lt; 0 {<br>            menuViewAngle += CGFloat(2 * Double.pi)<br>        }<br>        var index = cells.count - Int((menuViewAngle + CGFloat(Double.pi / 4)) / angle)<br>        if index == cells.count {<br>            index = 0<br>        }<br>        setSelectedIndex(index, animated: true)<br>    }<br>}</pre><pre>func handleTapGesture(_ sender: UITapGestureRecognizer) {<br>    let location = sender.location(in: menuLayerView)<br>    for (index, cell) in cells.enumerated() {<br>        if cell.path.contains(location) {<br>            setSelectedIndex(index, animated: true)<br>        }<br>    }<br>}</pre><h3>4.弹出收起动画</h3><pre>func openMenuView(withAnimate animate: Bool = true) {<br>    openMenu = true<br>    UIView.animate(withDuration: animate ? configure.animationDuration : 0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 5.0, options: .curveEaseInOut) {<br>        self.centerButton.transform = CGAffineTransform(rotationAngle: .pi * -0.5)<br>        self.centerButton.setImage(self.configure.closeImage, for: .normal)<br>        self.menuLayerView.transform = CGAffineTransform(scaleX: 1, y: 1).rotated(by: self.currentAngle)<br>    }<br>}</pre><pre>func closeMenuView(withAnimate animate: Bool = true) {<br>    openMenu = false<br>    let scale = (configure.centerRadius * 2) / bounds.width<br>    UIView.animate(withDuration: animate ? configure.animationDuration : 0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 5.0, options: .curveEaseInOut) {<br>        self.centerButton.transform = .identity<br>        self.centerButton.setImage(self.configure.openImage, for: .normal)<br>        self.menuLayerView.transform = CGAffineTransform(scaleX: scale, y: scale).rotated(by: self.currentAngle)<br>    }<br>}</pre><h3>5.内部细节</h3><p>考虑到方便布局和使用，内部使用 UIView叠加旋转实现，这里也可以采用 Layer直接绘制实现，相对 UIView ，层次结构会简单很多</p><h3>总结</h3><p>核心代码已经贴出，完整代码请查看 — — -&gt;&gt;&gt; <a href="https://github.com/JmoVxia/CLDemo">CLDemo</a> ，如果对你有所帮助，欢迎Star。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f08e445e4b08" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>