小编Iva*_*ino的帖子

加载时将ActivityIndi​​cator添加到UITableView的底部

我想在显示最后一个单元格时在我的UITableView底部添加一个ActivityIndi​​cator,而我正在获取更多数据,然后在获取数据时隐藏它.

所以我滚动到底部 - >显示的最后一行 - > spinner在获取数据时开始旋转 - >获取数据,隐藏微调器 - >添加到tableview的新数据.

关于如何实现这一目标的任何提示?

谢谢 ;)

uitableview uiactivityindicatorview ios swift3

14
推荐指数
3
解决办法
1万
查看次数

iOS - 在堆栈视图中以编程方式添加垂直线

我正在尝试以编程方式在堆栈视图内的标签之间添加垂直线.

所需的完成将是这样的图像:

stackview

我可以添加标签,所有标签都有所需的间距; 我可以添加水平线,但我无法弄清楚如何在中间添加这些分隔符垂直线.

我想这样做:

let stackView = UIStackView(arrangedSubviews: [label1, verticalLine, label2, verticalLine, label3])
Run Code Online (Sandbox Code Playgroud)

任何提示?

谢谢

uiview ios uistackview swift3

10
推荐指数
3
解决办法
1万
查看次数

文件管理器有时在文档目录中找不到子文件夹

我以前曾问过这个问题,但不得不重新制定一切,以便更容易理解.

在我的项目中,我使用以下代码在被documents directory调用内部创建了一个子文件夹HTML:

fileprivate func createFolderOnDocumentsDirectoryIfNotExists() {
    let folderName = "HTML"
    let fileManager = FileManager.default
    if let tDocumentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first {
        let filePath =  tDocumentDirectory.appendingPathComponent("\(folderName)")
        if !fileManager.fileExists(atPath: filePath.path) {
            do {
                try fileManager.createDirectory(atPath: filePath.path, withIntermediateDirectories: true, attributes: nil)
            } catch {
                print("Couldn't create document directory")
            }
        }
        print("Document directory is \(filePath)")
    }
}
Run Code Online (Sandbox Code Playgroud)

print语句打印以下内容:

文件目录是file:/// var/mobile/Containers/Data/Application/103869C9-9D46-4595-A370-A93BCD75D495/Documents/HTML

在我的应用程序里面,我Bundle有一个.css文件供我在一个HTML字符串中使用WKWebView.

由于.css文件需要与文件夹在同一个文件夹中HTML baseURL,我将该.css文件从 …

ios swift wkwebview

10
推荐指数
1
解决办法
546
查看次数

UIRefreshControl出现在集合视图项的顶部而不是后面

我有一个UICollectionView常规拉动刷新实现,但不知何故,微调器和"拉动刷新"文本出现在集合视图项目上方;

如何在物品后面制作它?

这是我添加UIRefreshControll到的方式UICollectionView

let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull down to refresh")
refreshControl.addTarget(self, action: #selector(pullToRefresh), for: UIControlEvents.valueChanged)
collectionView?.refreshControl = refreshControl
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uirefreshcontrol swift3

8
推荐指数
1
解决办法
2028
查看次数

在控制台中使用的有用的Xcode DEBUG命令

我一直想知道但是在Xcode中没有找到任何有用的命令列表.

我知道的一个,我使用的很多是输入命令的Backtrace bt,在遇到未捕获的异常之后的应用程序崩溃之后,它有时会给出问题所在的int.

你能分享更多有用的命令吗?它们可以让我们与调试器和应用程序本身进行交互吗?

谢谢

debugging xcode debug-backtrace ios

7
推荐指数
1
解决办法
6699
查看次数

每次迭代后AVPlayerLooper都会闪烁

我正在使用Apple的示例代码在UICollectionViewCell后台播放视频.

我正在使用AVPlayerLooper,因为它是同一视频的迭代.

我的问题在于,当视频到达终点时,它会显示一个轻微的黑屏双闪屏,也许正在寻找视频到0时间,我不确定.

这是代码:

Apple的协议

protocol Looper {

    init(videoURL: URL, loopCount: Int)

    func start(in layer: CALayer)

    func stop()
}
Run Code Online (Sandbox Code Playgroud)

Player Looper Class由Apple提供

// Code from Apple
class PlayerLooper: NSObject, Looper {
    // MARK: Types

    private struct ObserverContexts {
        static var isLooping = 0

        static var isLoopingKey = "isLooping"

        static var loopCount = 0

        static var loopCountKey = "loopCount"

        static var playerItemDurationKey = "duration"
    }

    // MARK: Properties

    private var player: AVQueuePlayer?

    private var playerLayer: AVPlayerLayer?

    private …
Run Code Online (Sandbox Code Playgroud)

ios avplayer uicollectionview swift

6
推荐指数
1
解决办法
700
查看次数

在推送上制作透明的导航栏,并在弹出时将其还原

我正在尝试创建一种效果,即使它接近我想要的效果,但也会出现一些UI故障,我将对此进行解释。

比方说,我有我的家庭导航控制器,我点击了一个单元格即可推送新的视图控制器。

在该视图控制器上,viewWillAppear(:)我实现了以下内容:

self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = .clear
self.navigationController?.navigationBar.tintColor = .white
self.navigationController?.navigationBar.barTintColor = .clear
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
Run Code Online (Sandbox Code Playgroud)

通过这样做,推视图控制器将拥有navigationBar透明的,并且仍然保持按钮可见(这是我愿意的话),但在推动动画,它显示了父控制器上的黑条,因为它隐藏了父母的navigationBar以及。

然后在推送视图控制器上,viewWillDisappear(_:)我实现了以下内容:

self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.backgroundColor = .white
self.navigationController?.navigationBar.barTintColor = .white
Run Code Online (Sandbox Code Playgroud)

通过这样做,我试图重置父级的navigationBar默认属性,但是这样做是在动画完成之前,我在动画过程中看到一个黑条,这会导致UI / UX变差。

我在这里做错什么了吗,还是有更好的方法呢?

谢谢。

uinavigationbar ios swift

6
推荐指数
1
解决办法
2004
查看次数

比较 Swift 4 中的两个 [String: Any] 字典

我有两个字典作为文本属性类型工作[String: Any],为了打开或关闭所需的属性,我需要检查两个字典是否相同。

我尝试了以下方法:

let current = inputTextView.typingAttributes

let undo = current.elementsEqual(attributes, by: { (arg0, arg1) -> Bool in
    return ((arg0.key == arg1.key) && (arg0.value == arg1.value))
})
Run Code Online (Sandbox Code Playgroud)

但是在第二次评估时,我得到了错误:

二元运算符“==”不能应用于两个“任意”操作数

这里比较两个类型的字典的最佳方法是什么[String: Any]

谢谢

nsdictionary ios swift4

6
推荐指数
1
解决办法
5028
查看次数

同时运行两个动画

我正在尝试使用两个视图创建动画,但在执行它们时遇到了一些意外行为。

我想在做第二个动画时为两个视图位置设置动画 transitionFlipFromBottom

这是代码:

let initialFrame = CGRect(x: xpos, y: -310, width: 300, height: 300)

let firstView = UIView()
firstView.backgroundColor = .red
firstView.frame = initialFrame

let secondView = UIView()
secondView.backgroundColor = .white
secondView.frame = initialFrame
secondView.isHidden = false


self.view.addSubview(firstView)
self.view.addSubview(secondView)


// Here I try to move the views on screen while fliping them
UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut, animations: {
    secondView.center = self.view.center
    firstView.center = self.view.center
    self.flip(firstView: firstView, secondView: secondView)
}, completion: nil)



// This function flips the views …
Run Code Online (Sandbox Code Playgroud)

uiviewanimation ios swift

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

拖放 - 从我的模型中创建一个NSItemProvider

让我们按部分去!

我正试图Drag and Drop在我的实施中实施UICollectionViewController.

该数据源UICollectionView是我创建array的自定义数据源Model Struct.

根据需要,我设置了我,collectionView.dragDelegate = self并通过这样做,我已经实现了required protocol function itemsForBeginning session: UIDragSession...

这是我的问题开始的地方:

struct Model {
    // some variables
    // Some initializations
}

var myModelDatasource: [Model] = [model1, model2, model3, ...] // it's a simple case example

func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
    let item = myModelDatasource[indexPath.row]

    let itemProvider = NSItemProvider(object: item)
    let dragItem = UIDragItem(itemProvider: itemProvider) // …
Run Code Online (Sandbox Code Playgroud)

drag-and-drop ios swift uidragitem

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