此行仅复制文本本身而不粘贴字体,并粘贴它:
pasteBoard.string = MainController.customTextView.text
Run Code Online (Sandbox Code Playgroud)
我尝试查看人们对这个问题的类似答案,但是我看到的几乎每个答案都在目标C中,并且已经过时。通过查看其他答案喜欢这个,我认为我得到了拷贝工作,但是当我粘贴复制的文本,它不糊什么。这是我要复制的功能:
@objc func handleCopyButton() {
MainController.customTextView.resignFirstResponder() // dismiss keyboard
// Setup code in overridden UITextView.copy/paste
let selectedRange = MainController.customTextView.selectedRange
let selectedText = MainController.customTextView.attributedText.attributedSubstring(from: selectedRange)
// UTI List
let utf8StringType = "public.utf8-plain-text"
let rtfdStringType = "com.apple.flat-rtfd"
// Try custom copy
do {
// Convert attributedString to rtfd data
let fullRange = NSRange(location: 0, length: selectedText.string.count)
let data:NSData? = try selectedText.data(from: fullRange, documentAttributes: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.rtfd]) as NSData
if let data = data {
// Set pasteboard …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取我选择的视频的缩略图.
它似乎确实创建了缩略图,但在将其上传到firebase时崩溃了
thumbnailStorageRef我相信它崩溃了.
这是相关的代码:
guard let imagePickerUrl = info[UIImagePickerControllerMediaURL] as? URL else { return }
let videoUrl = imagePickerUrl
// Generate image thumbnail.
let asset: AVAsset = AVAsset(url: videoUrl as URL)
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
var time = asset.duration
time.value = min(time.value, 3)
do {
let thumbnailImage = try imageGenerator.copyCGImage(at: time , actualTime: nil)
let image = UIImage(cgImage: thumbnailImage)
let imageData = UIImagePNGRepresentation(image)!
let thumbnailStorageRef = FIRStorage.storage().reference()
thumbnailStorageRef.child("thumbnails/" + randomString(length: 20) + ".png")
thumbnailStorageRef.put(imageData, metadata: …Run Code Online (Sandbox Code Playgroud) 当我点击一个单元格时,我想推送这个视图控制器.
这是我的代码:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let user = filteredUsers[indexPath.item]
print(user.username)
let userProfileController = UserProfileController(collectionViewLayout: UICollectionViewFlowLayout())
}
Run Code Online (Sandbox Code Playgroud)
我想推userProfileController.
注意:这UIView不是视图控制器
当应用程序崩溃时,它会在控制台中显示 (lldb)。不太确定为什么会崩溃。
但我很确定它与显示相机的功能有关:
let imagePicker: UIImagePickerController! = UIImagePickerController()
func shootADance() {
if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
//if the camera and rear camera is available, dod this
imagePicker.sourceType = .camera
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.allowsEditing = false
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
present(imagePicker, animated: true, completion: nil)
} else {
postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
}
} else {
postAlert("Camera inaccessable", message: "Application cannot access the camera.")
}
} …Run Code Online (Sandbox Code Playgroud)