小编Shi*_*k.p的帖子

如何将新属性添加到R​​ealm对象?

我正在尝试向Realm对象UserDetails添加一个新属性.这是我的尝试:

class CustomerDetails: Object {
   dynamic var customer_id = 0
   dynamic var customer_name = ""
}
Run Code Online (Sandbox Code Playgroud)

现在我需要将一个新属性"company_name"添加到之前已经创建的UserDetails对象中.如何向现有的Realm对象添加新的?

realm ios swift swift3

5
推荐指数
2
解决办法
3253
查看次数

如何在选择Swift 3.0上缩放UICollectionViewCell?

在此输入图像描述

在这里,我正在尝试突出显示选择的UICollectionViewCell,如图所示.我尝试将边框添加到选定的单元格,边框位于单元格内容视图中.这是我的尝试:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let cell = priorityCollectionView.cellForItem(at: indexPath)  as? BCPriorityListCollectionViewCell
    let borderWidth: CGFloat = 6
    cell?.contentView.frame = (cell?.labelBackground.frame.insetBy(dx: +borderWidth, dy: +borderWidth))!
    cell?.contentView.layer.borderColor = cell?.backgroundColor?.cgColor
    cell?.contentView.layer.borderWidth = borderWidth
}

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
    let cell = priorityCollectionView.cellForItem(at: indexPath)  as? BCPriorityListCollectionViewCell
    let borderWidth: CGFloat = 0
    cell?.contentView.frame = (cell?.labelBackground.frame.insetBy(dx: +borderWidth, dy: +borderWidth))!
    cell?.contentView.layer.borderColor = UIColor.clear.cgColor
    cell?.contentView.layer.borderWidth = borderWidth

}
Run Code Online (Sandbox Code Playgroud)

这该怎么做?

xcode ios uicollectionview uicollectionviewcell swift3

4
推荐指数
1
解决办法
2076
查看次数

仅适用于iPhone x的AVPlayer全屏问题

我使用Av播放器视图控制器创建了一个启动视频.它适用于所有设备,除了我的手机X.我尝试改变视频重力框架和一切,但它不会工作.关于这个的任何想法?这是示例代码:

guard let videoPath = Bundle.main.path(forResource: "Redtaxi-splash", ofType:"mov") else {
    return
}

let videoURL = URL(fileURLWithPath: videoPath)
let player = AVPlayer(url: videoURL)
playerViewController = AVPlayerViewController()
playerViewController?.player = player
playerViewController?.showsPlaybackControls = false
playerViewController?.view.frame = view.frame
playerViewController?.view.backgroundColor = .white
playerViewController?.view.contentMode = .scaleAspectFill


NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(note:)),
                                       name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)

view.addSubview((playerViewController?.view)!)
playerViewController?.player?.play()
Run Code Online (Sandbox Code Playgroud)

ios avplayer swift avplayerviewcontroller swift4

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

如何在领域 Swift 3 中列出属性

如何像在 SQL 中一样列出领域数据库中的属性SELECT columnName FROM mytable

这是我的尝试:let person = self.realm.objects(Person.self).filter("age")

realm ios swift

-1
推荐指数
1
解决办法
1683
查看次数