我正在尝试从Firebase订购我的数据,因此最新的帖子位于顶部(如Instagram),但我无法让它正常工作.我应该使用服务器时间戳吗?是否有"createdAt"字段?
func getPosts() {
POST_REF.observeEventType(.Value, withBlock: { snapshot in
guard let posts = snapshot.value as? [String : [String : String]] else {
print("No Posts Found")
return
}
Post.feed?.removeAll()
for (postID, post) in posts {
let newPost = Post.initWithPostID(postID, postDict: post)!
Post.feed?.append(newPost)
}
Post.feed? = (Post.feed?.reverse())!
self.tableView.reloadData()
}, withCancelBlock: { error in
print(error.localizedDescription)
})
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将两个重叠的 2 个视频合并为 2 秒。在这种重叠中,我想淡入第二个视频(或淡出第一个视频以显示第二个视频,任何一个都很棒)。
第一个视频按预期在结束前 2 秒淡出,但当它淡出时,我看到的是黑屏,而不是第二个视频淡入。在视频 1 结束时,视频 2 在动画淡入过程中显示了一半。
我看不到重叠的轨道,我做错了什么?下面是我的代码
func setupVideo() {
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "demoVideoTwo", ofType: "mp4")!)
let assetOne = AVAsset(url: url)
let urlTwo = URL(fileURLWithPath: Bundle.main.path(forResource: "demoVideoThree", ofType: "mp4")!)
let assetTwo = AVAsset(url: urlTwo)
let mixComposition = AVMutableComposition()
var instructions = [AVMutableVideoCompositionLayerInstruction]()
var mainInstructionList = [AVMutableVideoCompositionInstruction]()
var lastTime = CMTime.zero
// Create Track One
guard let videoTrack = mixComposition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)), let audioTrack = mixComposition.addMutableTrack(withMediaType: .audio, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)) else {
return …Run Code Online (Sandbox Code Playgroud)我在屏幕中间有一个黑色separatorView,分隔topContainerView(橙色)和bottomContainerView(绿色).可以使用panGesture上下拖动separatorView,但我无法获得顶视图和底视图来更新其约束并调整大小.橙色视图的底部和绿色视图的顶部应始终与separatorView一起使用.
这是我的代码(UPDATED包含变量声明):
let separatorView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.black
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let topContainerView : UIView = {
let view = UIView()
view.backgroundColor = UIColor.orange
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let bottomContainerView : UIView = {
let view = UIView()
view.backgroundColor = UIColor.green
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.addViews()
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(detectPan(recognizer:)))
panGesture.delaysTouchesBegan = false
panGesture.delaysTouchesEnded = false
separatorView.addGestureRecognizer(panGesture)
}
override …Run Code Online (Sandbox Code Playgroud)