在我的项目中,我有多种类型的UITableview单元格,每个单元格都包含UICollectionview。
最初,我tableViewcell在的2个部分中加载了2个UITableview。最初,它加载得很好,没有任何问题。如果我滚动第一部分,滚动效果很好,但是当我尝试滚动第二部分时,出现以下错误:
从-collectionView:cellForItemAtIndexPath:返回的单元格没有reuseIdentifier-必须通过调用-dequeueReusableCellWithReuseIdentifier:forIndexPath来检索单元格:
我有以下代码来设置流程:
class Home: UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource{
override func viewDidLoad() {
self.tableView.register(SliderViewCell.nib, forCellReuseIdentifier: SliderViewCell.identifier)
self.tableView.register(GridViewCell.nib, forCellReuseIdentifier: GridViewCell.identifier)
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let viewObj = self.viewObject[indexPath.section]
if viewObj.itemType! == HomeViewItemType.Slider.rawValue{
if let sliderCell = cell as? SliderViewCell {
sliderCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
}
}
else if viewObj.itemType! …Run Code Online (Sandbox Code Playgroud) 我需要像这样创建一个左上角和左下角半径的按钮
.我尝试创建以下扩展,取自stackoverflow之一:
extension UIButton {
func roundCorners(corners:UIRectCorner, radius: CGFloat) {
self.layer.borderColor = GenerateShape.UIColorFromHex(0x989898, alpha: (1.0-0.3)).CGColor
self.layer.borderWidth = 1.0
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
}
}
Run Code Online (Sandbox Code Playgroud)
然后调用这样的方法:
self.collectionBtn.roundCorners(.TopLeft | .BottomLeft, radius: cornerRadius)
Run Code Online (Sandbox Code Playgroud)
那么为什么左上角和左下角看不见呢?我该怎么办才能让它们可见?
我正在从 UIImage 数组制作视频。我成功地做到了并且所有图像都显示在视频中。我正在使用 AVAssetExportSession 导出视频,该视频也可以正常工作,除非我使用 AVAssetExportSession videoComposition 属性时,视频仅显示第一张图像。这是我的代码:
func mergeAudioVideoFiles(videoUrl:NSURL, audioUrl:NSURL)->NSURL
{
let mixComposition : AVMutableComposition = AVMutableComposition()
var mutableCompositionVideoTrack : [AVMutableCompositionTrack] = []
var mutableCompositionAudioTrack : [AVMutableCompositionTrack] = []
let totalVideoCompositionInstruction : AVMutableVideoCompositionInstruction = AVMutableVideoCompositionInstruction()
//start merge
let aVideoAsset : AVAsset = AVAsset(URL: videoUrl)
let aAudioAsset : AVAsset = AVAsset(URL: audioUrl)
mutableCompositionVideoTrack.append(mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid))
mutableCompositionAudioTrack.append( mixComposition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: kCMPersistentTrackID_Invalid))
let aVideoAssetTrack : AVAssetTrack = aVideoAsset.tracksWithMediaType(AVMediaTypeVideo)[0]
let aAudioAssetTrack : AVAssetTrack = aAudioAsset.tracksWithMediaType(AVMediaTypeAudio)[0]
do{
try mutableCompositionVideoTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, aVideoAssetTrack.timeRange.duration), ofTrack: aVideoAssetTrack, atTime: kCMTimeZero)
try …Run Code Online (Sandbox Code Playgroud)