小编chi*_*uda的帖子

动态高度UITableViewCell内的动态高度UICollectionView

我将水平UICollectionView固定到的所有边缘UITableViewCell。集合视图中的项目是动态调整大小的,我想使表视图的高度等于最高的集合视图单元格的高度。

视图的结构如下:

UITableView

UITableViewCell

UICollectionView

UICollectionViewCell

UICollectionViewCell

UICollectionViewCell

class TableViewCell: UITableViewCell {

    private lazy var collectionView: UICollectionView = {
        let collectionView = UICollectionView(frame: self.frame, collectionViewLayout: layout)
        return collectionView
    }()

    var layout: UICollectionViewFlowLayout = {
        let layout = UICollectionViewFlowLayout()
        layout.estimatedItemSize = CGSize(width: 350, height: 20)
        layout.scrollDirection = .horizontal
        return layout
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        let nib = UINib(nibName: String(describing: CollectionViewCell.self), bundle: nil)
        collectionView.register(nib, forCellWithReuseIdentifier: CollectionViewCellModel.identifier)

        addSubview(collectionView)

        // (using SnapKit)
        collectionView.snp.makeConstraints …
Run Code Online (Sandbox Code Playgroud)

uitableview ios uicollectionview swift

21
推荐指数
2
解决办法
925
查看次数

保存当前的GIDGoogleUser,而不是每次启动时都登录

我正在用GIDSignInButton我的用户签到谷歌.问题是,我不确定如何保存当前用户,以便每个用户每次打开应用程序时都不必登录.我尝试过使用signInSilently()The operation couldn’t be completed. (com.google.GIDSignIn error -4.)每次都得到.

头文件中的错误说明了这一点:

// Indicates there are no auth tokens in the keychain. This error code will be returned by
  // signInSilently if the user has never signed in before with the given scopes, or if they have
  // since signed out.
  kGIDSignInErrorCodeHasNoAuthInKeychain = -4,
Run Code Online (Sandbox Code Playgroud)

就我而言,用户已经使用给定的范围登录,但他们还没有退出.所以我不确定是什么导致了这个错误.

用户登录后,如何将该实例保存到我signInSilently()之后可以使用的位置?是否还涉及刷新和访问令牌?

ios google-oauth swift

17
推荐指数
1
解决办法
1785
查看次数

切换分支时Xcode总是冻结

使用Xcode 8的内置源代码控制时,在两个分支之间切换几乎总是会导致Xcode冻结并需要强制退出应用程序.我的分支并不是特别分开.看起来不像是耗费过多的内存或CPU.这是怎么回事?

git xcode

12
推荐指数
1
解决办法
579
查看次数

如何在后台模式下继续播放音频

我有一个UIWebView,可以在我的视图控制器中播放视频片段.当我退出应用程序时,音频将停止播放,虽然我可以按控制中心的播放再次继续播放.为此,我在AppDelegate.swift中使用以下代码.

当应用程序进入后台时,我希望音频自动开始播放.如何启用MPMusicPlayerController/AVAudioPlayer(我真的不确定它是什么)继续播放,这样用户就不必手动按播放了?

我还在目标设置中的背景模式下选中了"音频和Airplay",并将所需背景模式设置为"App播放音频或使用AirPlay传输音频/视频".

var error: NSError?
var success = AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: &error)
if !success {
     NSLog("Failed to set audio session category.  Error: \(error)")
}
Run Code Online (Sandbox Code Playgroud)

更新:我正在创建一个自定义视图appDel以容纳视频迷你播放器.这就是我创造它的方式.CustomWindow是一个自定义类UIWindow,我将迷你播放器添加到视图层次结构的顶部.在这段代码中,我在创建之前调用该方法UIWebView吗?

class AppDelegate: UIResponder, UIApplicationDelegate {

    let myWind = CustomWindow(frame:UIScreen.mainScreen().bounds)
    var window: UIWindow? {
        set {

        }
        get {
            return myWind
        }
    }

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        var error: NSError?
        var success = AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: &error)
        if success {
            AVAudioSession.sharedInstance().setActive(true, error: nil) …
Run Code Online (Sandbox Code Playgroud)

audio ios

11
推荐指数
1
解决办法
2680
查看次数

Choppy CATextLayer动画:同时使用fontSize +位置

我需要一个动画CATextLayerbounds.size.height,positionfontSize.当我将它们添加到a时CAAnimationGroup,文本会在动画期间抖动,就像这样:

https://youtu.be/HfC1ZX-pbyM

fontSize使用bounds.size.heightAND/OR 进行动画制作时,文本的跟踪值(字符间距)的抖动似乎发生了position.我已经孤立fontSize,并且它自身表现良好.

CATextLayer如果我同时为边界和字体大小设置动画,如何防止文本抖动?


编辑

我已经开始动画了bounds.现在,我只关心fontSize+ position.这是两个显示差异的视频.

fontSize只(顺利):https://youtu.be/FDPPGF_FzLI

fontSize+ position(紧张):https://youtu.be/3rFTsp7wBzk

这是代码.

    let startFontSize: CGFloat = 16
    let endFontSize: CGFloat = 30

    let startPosition: CGPoint = CGPoint(x: 40, y: 100)
    let endPosition: CGPoint = CGPoint(x: 20, y: 175)

    // Initialize the layer

    textLayer = CATextLayer()
    textLayer.string = …
Run Code Online (Sandbox Code Playgroud)

core-animation ios swift

11
推荐指数
1
解决办法
860
查看次数

没有从后台的didReceiveScriptMessage获得回调

我有一个WKWebView()播放嵌入式视频.在每个视频结束后,我从Javascript获得一个回调消息,其中索引号应该是应该加载的数组中的下一个视频.

当应用程序位于前台时,它可以很好地工作,当我按下睡眠/唤醒(锁定)按钮时.然而,当我按下主页按钮时,WKWebView停止接收消息并且从不加载下一个视频.

当我按下主页按钮时,是否有原因导致Web视图无响应?它UIWebView在iOS8中运行良好,但我不得不切换到WKWebView因为它允许在后台播放音频.

我正在使用的代码非常基本,如下所示:

func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {

        if(message.name == "callbackHandler") {

              print(message.body)
        }
}
Run Code Online (Sandbox Code Playgroud)

相比之下,我得到func webView(shouldStartLoadWithRequest)了一个回应UIWebView.任何理由WKWebView都会有所不同?或者我应该使用的是另一个功能didReceiveScriptMessage吗?

uiwebview ios swift wkwebview

8
推荐指数
0
解决办法
595
查看次数

EXC_BAD_ACCESS KERN_INVALID_ADDRESS崩溃

我的应用程序在调试模式下通过Xcode运行良好,但无论何时通过TestFlight下载,它都会因此错误而崩溃:EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000200013f7b9e78.

它在这条线上崩溃了.我specialized Array.withUnsafeMutableBufferPoint在这个堆栈跟踪中看到它可能与之相关.

self.array.sortInPlace. {
                (($0 as Dictionary<String, AnyObject>)["time"] as? String) > (($1 as Dictionary<String, AnyObject>)["time"] as? String)
            }
Run Code Online (Sandbox Code Playgroud)

在我使用的Swift 1.3中sort,现在在Swift 2中我正在使用sortInPlace.不确定这是否有所作为,但我确实知道sort没有调用结果,因为它是不可变的.

Thread : Crashed: com.apple.main-thread
    0  libswiftCore.dylib             4302688056 _swift_retain_(swift::HeapObject*) + 8
    1  App                          4295962040 specialized LiveFeedViewController.(viewDidLoad(LiveFeedViewController) -> () -> ()).(closure #3).(closure #1) (LiveFeedViewController.swift)
    2  App                          4295785356 specialized thunk (LiveFeedViewController.swift)
    3  App                          4295953880 specialized _siftDown<A where ...> (inout A, A.Index, Range<A.Index>, inout (A.Generator.Element, A.Generator.Element) -> Bool) -> () …
Run Code Online (Sandbox Code Playgroud)

exc-bad-access ios swift

8
推荐指数
3
解决办法
7699
查看次数

对单一存储库中的资产进行重复数据删除

我的文件结构如下:

- packages
    - app1
        - node_modules
            - shared
        - public
            - svg1
        - src/pages
    - app2
        - node_modules
            - shared
        - public
            - svg1
        - src/pages
    - shared
        - src/components
Run Code Online (Sandbox Code Playgroud)

我使用 Lerna 与shared我的app1app2包共享包中的 React 组件,例如,我的app1 package.json.dependenciesinclude "shared": "^1.0.0"

我在共享组件时没有问题,但不确定如何共享资源(例如 .png 和 .svg 文件)。目前有效的方法是将所有资产(请参阅 svg1)添加到public中的文件夹中,但我想对它们进行重复数据删除。app1app2

例如,在我的一个shared组件中,我只是使用 引用 .svg <img src="svg1.svg" alt="MyLogo" />,但图像仅在app1包含在app1包中时才会加载。

如何将这些资源保留在包中并在、或组件shared中引用它们?app1app2shared

reactjs lerna monorepo

7
推荐指数
0
解决办法
584
查看次数

在iOS中模拟YouTube Mini Player

在YouTube应用中,我可以通过最右下角的迷你播放器继续观看视频(请参阅下面标题为"The Chainsmokers"的视频),当我浏览应用时,该视频会叠加在所有其他视图控制器上.无论我在哪个页面,我都可以在迷你播放器中观看视频.

如果从迷你播放器向上拖动,将显示视频的整个视图控制器.但它总是在其他页面上.我正在尝试了解如何使用Swift复制此方法,以便我可以从任何页面观看视频.

我的应用程序的结构方式是通过UIPageViewController.我嵌入了三个独特的导航控制器(用于滑动导航目的(见下面的代码)).我想了解如何利用迷你播放器.在YouTube中,是否像迷你模式VC?它是如何在结构上布局的,如果您知道,我如何将其纳入我当前的布局?

class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

    private var pages: [UINavigationController]!

    private var currentPageIndex: Int!

    override func viewDidLoad() {
        super.viewDidLoad()
            self.dataSource = self
            self.delegate = self

            self.pages = [
                self.storyboard!.instantiateViewControllerWithIdentifier("Nav1") as! UINavigationController,
                self.storyboard!.instantiateViewControllerWithIdentifier("Nav2") as! UINavigationController,
                self.storyboard!.instantiateViewControllerWithIdentifier("Nav3") as! UINavigationController
            ]

            (self.pages[0].topViewController as! Nav1).parentPageViewController = self
            (self.pages[1].topViewController as! Nav2).parentPageViewController = self
            (self.pages[2].topViewController as! Nav3).parentPageViewController = self


            self.currentPageIndex = 1
            let startingViewController = self.pages[1] as UINavigationController
            self.setViewControllers([startingViewController], direction: .Forward, animated: false, completion: nil)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController …
Run Code Online (Sandbox Code Playgroud)

youtube ios swift

5
推荐指数
1
解决办法
2986
查看次数

获取 UILabel 中的每一行文本

我正在尝试将 aUILabel中的每一行添加到数组中,但我使用的代码似乎并不十分准确。

func getLinesArrayOfStringInLabel(label:UILabel) -> [String] {

    guard let text: NSString = label.text as? NSString else { return [] }
    let font:UIFont = label.font
    let rect:CGRect = label.frame

    let myFont: CTFont = CTFontCreateWithName(font.fontName as CFString, font.pointSize, nil)

    let attStr:NSMutableAttributedString = NSMutableAttributedString(string: text as String)
    attStr.addAttribute(NSAttributedStringKey.font, value:myFont, range: NSMakeRange(0, attStr.length))

    let frameSetter:CTFramesetter = CTFramesetterCreateWithAttributedString(attStr as CFAttributedString)

    let path: CGMutablePath = CGMutablePath()
    path.addRect(CGRect(x: 0, y: 0, width: rect.size.width, height: 100000))

    let frame:CTFrame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, nil)
    let lines …
Run Code Online (Sandbox Code Playgroud)

core-text ios swift

5
推荐指数
1
解决办法
2491
查看次数