SlangKing — map and player profile update

The key for app users to interact with the world is the map. By finding other users or players on the map constructs a mature social network for the specific app. The close feeling of nearby players give the user sense of secure and identity.

There are 3 features updated:

1. MapKit

2. Social image share

Add a new func with extension in UIView to screenshot the player profile page

//UIView extension which converts the UIView into an image.
extension UIView {
func toImage() -> UIImage {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)

drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)

let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}

Then present the UIActivityViewController with activityItems:[screenshot].

@IBAction func shareButtonPressed(_ sender: Any) {let activityController = UIActivityViewController(activityItems: [self.view.toImage()], applicationActivities: nil)present(activityController, animated: true, completion: nil)}

3. Input image with camera or photo library

By using UIAlertController and UIImagePickerController gives the player two options to input their head photo.

UIImagePickerController:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {print(“info \(info)”)let image = info[UIImagePickerControllerOriginalImage] as? UIImagemainPlayerImageView.image = imagedismiss(animated: true, completion: nil)}

UIAlertController:

@IBAction func changePhotoButton(_ sender: Any) {func chooseHowToPhoto() {// setting alertControllerlet alertController = UIAlertController(title: “Photo”, message: “Choose from”, preferredStyle: .actionSheet)// getting photo by cameralet cameraAction = UIAlertAction(title: “Camera”, style: .default) {(action: UIAlertAction!) -> Void inlet imagePicker = UIImagePickerController()imagePicker.allowsEditing = trueimagePicker.sourceType = .cameraimagePicker.delegate = selfself.present(imagePicker, animated: true, completion: nil)}// getting photo by photo librarylet photolibraryAction = UIAlertAction(title: “Photo Library”, style: .default) {(action: UIAlertAction!) -> Void inlet imagePicker = UIImagePickerController()imagePicker.allowsEditing = trueimagePicker.sourceType = .photoLibraryimagePicker.delegate = selfself.present(imagePicker, animated: true, completion: nil)}// add additional cancel buttonlet cancelAction = UIAlertAction(title: “Cancel”, style: .cancel, handler: nil)alertController.addAction(cameraAction)alertController.addAction(photolibraryAction)alertController.addAction(cancelAction)self.present(alertController, animated: true, completion: nil)}chooseHowToPhoto()}

Also the data passing between controllers by func prepare and unwind segue. It will be updated to Notification to updated all the data to the game rather then profile only.

--

--