I am trying to send a photo and video from one controller to another with the YPImagePicker pod. I am having an issue understanding how to use this file.
var selectedItems = [YPMediaItem]()
let selectedImageV = UIImageView()
#objc func showPicker() {
var config = YPImagePickerConfiguration()
config.library.mediaType = .photoAndVideo
config.library.onlySquare = true
config.showsFilters = false
config.shouldSaveNewPicturesToAlbum = true
config.albumName = "RecipeSharing"
config.video.compression = AVAssetExportPresetMediumQuality
config.startOnScreen = .library
config.screens = [.library, .photo, .video]
config.video.recordingTimeLimit = 5.0
config.video.libraryTimeLimit = 500.0
config.video.trimmerMaxDuration = 60.0
config.video.trimmerMinDuration = 3.0
config.video.fileType = .mov
config.showsCrop = .rectangle(ratio: (16/9))
config.targetImageSize = YPImageSize.original
config.wordings.libraryTitle = "Gallery"
config.hidesStatusBar = false
config.hidesBottomBar = false
config.library.maxNumberOfItems = 5
let picker = YPImagePicker(configuration: config)
picker.didFinishPicking { [unowned picker] items, _ in
if let photo = items.singlePhoto {
let finalShareVC = NewInstructionsController()
picker.navigationController?.pushViewController(finalShareVC, animated: true)
}
}
picker.didFinishPicking { [unowned picker] items, _ in
if let video = items.singleVideo {
let finalShareVC = NewInstructionsController()
picker.navigationController?.pushViewController(finalShareVC, animated: true)
}
}
present(picker, animated: true, completion: nil)
}
My Second Controller has the the code as the following.
var selectedImage: UIImage? {
didSet {
guard let image = selectedImage else { return }
instructionsImage.image = image
}
}
This is used to receive the file the photo I believe. Does anyone know what I have to use to send a photo and video to another controller so that it can be used. I have tried reading a lot on this pod. I get to the save option in this pod and then it does not do anything. I was wondering if anyone had an idea or could help me. Maybe I dont need to push the view but I am unsure. Thank you.
Related
UIImages and UILabel are disappearing in some collectionViews after refreshing inside my app.
here is my code. You can see what is wrong in the picture, the left image is before refreshing and there is a discount price label and after refreshing the simulator, it is gone. getProductLatestData(), getBestSellingData() are the Alamofire get request for API.
//For Refresh Controller
//----------------------
var player : AVAudioPlayer
var refreshController : UIRefreshControl = {
let refreshController = UIRefreshControl()
refreshController.addTarget(self, action: #selector(updateData), for: .valueChanged)
return refreshController
}()
//----------------------
//For Update Data when scroll to top
//----------------------------------
#objc func updateData(){
//To play sound when scroll top
//-----------------------------
let pathToSound = Bundle.main.path(forResource: "Flick", ofType: "wav")
let url = URL(fileURLWithPath: pathToSound!)
do {
player = try AVAudioPlayer(contentsOf: url)
player?.play()
} catch let error {
print(error.localizedDescription)
}
//-----------------------------
//Fetch Latest Products Data
getProductLatestData(pageNumber: 0, pageSize: 0)
//Fetch BestSelling Products Data
getBestSellingData(pageNumber: 0, pageSize: 0)
//Fetch Promotion Products Data
getPromotionProductsData(pageNumber: 0, pageSize: 0)
//Fetch Products By Category
getProductsByCat(pageNumber: 0, pageSize: 0)
//Fetch Reward Products
getRewardProducts()
self.refreshController.endRefreshing()
}
if collectionView == latestItemCV {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "latestItemCell", for: indexPath) as! PromotionItemsCollectionViewCell
if let percent = latestItemData[indexPath.row].promotePercent {
if percent != 0 {
cell.percentOff.isHidden = false
cell.percentOff.text = " \(percent) % Off "
cell.percentOffBackground.isHidden = false
}
else{
cell.percentOff.isHidden = true
cell.percentOffBackground.isHidden = true
}
}
if let name = latestItemData[indexPath.row].name {
cell.itemsName.text = name
}
else{
cell.itemsName.text = "-"
}
if let url = latestItemData[indexPath.row].url {
cell.itemsImageView.sd_setImage(with: URL(string: url), placeholderImage: UIImage(named: "placeholder"))
}
//----------------------------------
Thanks to #larme I recheck the code here is how I fixed it, I added those disappeared labels isHidden = false also as I did isHidden = true for them.
if let promotionPrice = latestItemData[indexPath.row].promotePrice {
if promotionPrice != 0 {
cell.originalItemsPrice.text = "\(setCommaForPrice(price: Int(promotionPrice))) Ks"
cell.promotionPercent.isHidden = false
cell.promotionLine.isHidden = false
}
else{
if let orPrice = latestItemData[indexPath.row].originalPrice {
cell.originalItemsPrice.text = "\(setCommaForPrice(price: Int(orPrice))) Ks"
}
cell.promotionPercent.isHidden = true
cell.promotionLine.isHidden = true
}
}
I am displaying cards data from my model array, how do i randomize card data everytime i start the app and should not be repetitive. I am using ZLSwipeable view library for creating cards fro swipe feature. this is the function in which i have write all my code for swipe cards, and in the code wordsdata is the model array that i have declaredlike this var wordsdata = ModelRsult.
CardView is the view i am displaying my cards into
screenshot of my card display screen
in the image it is shown banana as the first data, now when i run the app again it should show me another data first and so on
my source code:
func nextCardView() -> UIView?
{
let arrayData = wordsData
if (self.colorIndex >= arrayData.count)
{
return nil
}
let cardView = CardView(frame: swipeableView.bounds)
if loadCardsFromXib
{
let contentView = Bundle.main.loadNibNamed("CardContentView", owner: self, options: nil)?.first! as! CardView
contentView.superVC = self
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.backgroundColor = cardView.backgroundColor
cardView.addSubview(contentView)
let data = arrayData[(self.colorIndex)] as ModelResult
contentView.wordModel = data
let savedValue = UserDefaults.standard.bool(forKey: "isLangChanged")
tempLangChanged = savedValue
if tempLangChanged == false
{
if let spanishName = data.cardWordEnglish, spanishName.count != 0
{
contentView.wordSpanish.text = spanishName
print(spanishName)
}
}
else
{
if let dict = data.cardWordImage, dict.count != 0
{
let url = WS_wordIconUrl + dict
contentView.wordImage.kf.indicatorType = .activity
contentView.wordImage.kf.setImage(with: URL(string: url))
}
if let spanishName = data.cardWordSpanish, spanishName.count != 0
{
contentView.wordSpanish.text = spanishName
print(spanishName)
}
}
contentView.soundBtn.addTarget(self, action:#selector(self.soundBtn(sender:)), for: .touchUpInside)
contentView.hideCard.addTarget(self, action:#selector(self.hideCard(sender:)), for: .touchUpInside)
contentView.soundBtn.tag = self.colorIndex
contentView.hideCard.tag = self.colorIndex
cardView.tag = self.colorIndex
constrain(contentView, cardView) { view1, view2 in
view1.left == view2.left
view1.top == view2.top
view1.width == cardView.bounds.width
view1.height == cardView.bounds.height
}
}
colorIndex += 1
return cardView
}
The best way for this problem is to shuffle the array where your cards are and then use it. In your case, I would shuffle it at the app start.
array.shuffle()
The error said that 'new()' is unavailable for Swift::use object initializers instead. Don't know how to fix...
func showImage(notif:NSNotification) {
if let userInfo = notif.userInfo as NSDictionary! {
//the code below is the one i got error for
let photos:NSMutableArray = NSMutableArray.new()
let photo:IDMPhoto = IDMPhoto(image: userInfo["img"] as! UIImage!)
photos.addObject(photo)
let browser:IDMPhotoBrowser = IDMPhotoBrowser(photos: photos as [AnyObject]!)
browser.delegate = self
browser.displayActionButton = false
self.presentViewController(browser, animated: true, completion: nil)
}
}
Simply change NSMutableArray.new() to NSMutableArray().
I have my text which doesn't display in the debug area it says
"[6384:3178597] plugin com.apple.share.Facebook.post invalidated"
The code which I have been using is the following:
#IBAction func Share(sender: AnyObject) {
let firstActivityItem = " Hello "
let ActivityViewController : UIActivityViewController = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
self.presentViewController(ActivityViewController, animated: true, completion: nil)
}
also if anyone can give me the code to add an image and a link to the action sheet it would also be very helpful
Follow this example:
class DataToShow{
var url: String = ""
var text: String = ""
var image: UIImage?
}
var myData: DataToShow!
#IBAction func shareButtonClick(sender: UIButton) {
let firstActivityItem = myData.text
let secondActivityItem : NSURL = NSURL(string: myData.url)!
let image : UIImage? = myData.image
var activities = [firstActivityItem, secondActivityItem]
if image != nil{
activities.append(image!)
}
let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: activities, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros
//This part is to center it on current UIViewController
let x = self.view.center
activityViewController.view.frame.origin.x = x.x
activityViewController.view.frame.origin.y = x.y
activityViewController.popoverPresentationController?.sourceRect = CGRectMake(x.x, x.y, 0, 0)
activityViewController.popoverPresentationController?.delegate = self
self.presentViewController(activityViewController, animated: true, completion: nil)
}
//This is for maintening it centered when changing orientation...
override func popoverPresentationController(popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverToRect rect: UnsafeMutablePointer<CGRect>, inView view: AutoreleasingUnsafeMutablePointer<UIView?>) {
let x = popoverPresentationController.presentingViewController.view.center
var newRect = CGRectMake(x.x , x.y, 0, 0)
rect.initialize(newRect)
}
This has been tested on iPad and iPhone. Centered part of the code is just for iPad, on IPhone it behaves different.
Ive looked around at other answers, but nothing seems to be helping my case.
I have a viewController class which contains an IBAction for a button. This button should open a NSOpenPanel as a sheet from that viewController:
class ViewController: NSViewController {
#IBAction func folderSelection(sender: AnyObject) {
var myFiledialog: NSOpenPanel = NSOpenPanel()
myFiledialog.prompt = "Select path"
myFiledialog.worksWhenModal = true
myFiledialog.allowsMultipleSelection = false
myFiledialog.canChooseDirectories = true
myFiledialog.canChooseFiles = false
myFiledialog.resolvesAliases = true
//myFiledialog.runModal()
myFiledialog.beginSheetModalForWindow(self.view.window!, completionHandler: nil)
var chosenpath = myFiledialog.URL
if (chosenpath!= nil)
{
var TheFile = chosenpath!.absoluteString!
println(TheFile)
//do something with TheFile
}
else
{
println("nothing chosen")
}
}
}
The problem comes from myFileDialog.beginSheetModalForWindow(..) , it works with the line above, but that is not a sheet effect
You need to call beginSheetModalForWindow from your panel on your window, and use a completion block:
let myFiledialog = NSOpenPanel()
myFiledialog.prompt = "Select path"
myFiledialog.worksWhenModal = true
myFiledialog.allowsMultipleSelection = false
myFiledialog.canChooseDirectories = true
myFiledialog.canChooseFiles = false
myFiledialog.resolvesAliases = true
myFiledialog.beginSheetModalForWindow(window, completionHandler: { num in
if num == NSModalResponseOK {
let path = myFiledialog.URL
print(path)
} else {
print("nothing chosen")
}
})
Swift 5
let dialog = NSOpenPanel()
dialog.beginSheetModal(for: self.view.window!){ result in
if result == .OK, let url = dialog.url {
print("Got", url)
}
}