Üst düzey tasarım projem için kayan kiremit puzzle uygulaması yapmaya çalışıyorum. Uygulamanın bir fotoğraf seçmesi veya alması (bunu anladım), ardından uygulamanın 9 parçaya (kırpılmış görüntüler) kesmesi ve bunları bir dizide saklaması, ardından bir tane kaldırması ve bunları rastgele bir sırada göstermesi ekran. Son olarak, kullanıcı doğru sırada düzenlenmiş olana kadar fayanslara dokunur veya kaydırır.iOS Sürgülü Bulmaca Swift
Çevrimiçi olarak çeşitli kod örnekleri buldum, ancak hiçbiri Swift'de yazılmadı. Bulduğum ve Swift'de yeniden yazdığım eski kodu yorumlamaya çalıştığımda, her türlü hataları alırım ... Tüm bunlarla birlikte bir öğrenci benciliyim.
displayImageView'da görüntülenen kullanıcı tarafından seçilen görüntüden yeni kırpılmış görüntüler oluşturmak için CGSizeMake, CGRectMake ve CGImageCreateWithImageInRect'i kullanmaya çalışıyorum ve bu yeni kırpılmış görüntü parçalarını tileStack dizisine depolayın. Ama sanırım bir şeyi özlüyorum ... belki de çok fazla özlüyorum. Bir screenshot of the error when I run it.
//PhotoViewController.swift Created by Jim on 2/18/16. Copyright © 2016 JamesDphoto.com. All rights reserved.
import UIKit import Foundation
class PhotoViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var tileStack = [AnyObject]();
//Beginning of simple image selection and display
@IBOutlet weak var displayImageView: UIImageView!
@IBAction func choosePicFromLibrary(sender: AnyObject) {
let imagePicker: UIImagePickerController = UIImagePickerController()
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.delegate = self
imagePicker.modalPresentationStyle = UIModalPresentationStyle.Popover
if (imagePicker.popoverPresentationController != nil) {
imagePicker.popoverPresentationController!.sourceView = sender as! UIButton
imagePicker.popoverPresentationController!.sourceRect = (sender as! UIButton).bounds
}
presentViewController(imagePicker, animated: true, completion: nil)
}
@IBAction func takePhoto(sender: AnyObject) {
let imagePicker: UIImagePickerController = UIImagePickerController()
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.delegate = self
imagePicker.modalPresentationStyle = UIModalPresentationStyle.Popover
if (imagePicker.popoverPresentationController != nil) {
imagePicker.popoverPresentationController!.sourceView = sender as! UIButton
imagePicker.popoverPresentationController!.sourceRect = (sender as! UIButton).bounds
}
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
dismissViewControllerAnimated(true, completion: nil)
displayImageView.image = info[UIImagePickerControllerOriginalImage] as! UIImage!
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}
//Beginning of function to cut photo into 9 tiles, then randomize them.
//cut into 9 tiles and add to tileStack array
@IBAction func randomize(sender: AnyObject) {
let tileSize = CGSizeMake(displayImageView.image!.size.width/3, displayImageView.image!.size.height/3)
for var rowI = 0; rowI < 3; rowI++
{
for var colI = 0; colI < 3; colI++
{
let tileRect = CGRectMake(CGFloat(rowI) * tileSize.width, tileSize.height * CGFloat(colI), tileSize.width, tileSize.height)
let tileImage = CGImageCreateWithImageInRect(displayImageView.image as! CGImage!, tileRect)
tileStack.append(tileImage!)
}
}
//display tiles in order on screen
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Sen hata görüntülere bağlantıları, düz metin olarak hata sonrası olmamalıdır tercih ediyorum. Ayrıca konsolda bir ileti almanız gerekir (büyük olasılıkla, hata ayıklanırken hatayla karşılaşılır) – nhgrif
Bir şey için, hızlıca 'CGRectMake', 'CGSizeMake' vb. 'Lere gerek yoktur, sadece kurucuları kullanın:' CGSize (genişlik :, yükseklik:) ', vb –
Gönderme tüm ipuçları için teşekkürler, nhgrif! –