我在swift中使用AVFoundation来拍照,但我无法将任何func代码行从Objective c转换为Swift.我的功能代码是:
- (void) capImage { //method to capture image from AVCaptureSession video feed
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo] ) {
videoConnection = connection;
break;
}
}
if (videoConnection) {
break;
}
}
NSLog(@"about to request a capture from: %@", stillImageOutput);
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if (imageSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
[self processImage:[UIImage imageWithData:imageData]];
}
}]; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的Swift应用程序的viewController中添加图像背景,但colorWithPatternImage不可用..还有其他形式或者必须将其添加到imageView中吗?
我正在尝试使用此代码:
let imageName = "image.png"
self.view.backgroundColor = UIColor.colorWithPatternImage(UIImage(named:imageName))
Run Code Online (Sandbox Code Playgroud)
谢谢!
我需要将Objective-C转换为Swift以从通讯簿中获取联系人的图像.但是,我得到一个错误与投从CFData到NSData,我不知道如何使这项工作.我该怎么做才能使这项工作正常进行?
在Objective-C中:
ABRecordID contactID = ABRecordGetRecordID(contactRef);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef origContactRef = ABAddressBookGetPersonWithRecordID(addressBook, contactID);
if (ABPersonHasImageData(origContactRef)) {
NSData *imgData = (NSData*)ABPersonCopyImageDataWithFormat(origContactRef, kABPersonImageFormatOriginalSize);
img = [UIImage imageWithData: imgData];
[imgData release];
}
CFRelease(addressBook);
return img;
Run Code Online (Sandbox Code Playgroud)
在Swift中:
var image: UIImage!
if ABPersonHasImageData(person) {
var imgData = (ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatOriginalSize))
image = UIImage.imageWithData(imgData) //Here get the error
}
Run Code Online (Sandbox Code Playgroud) 如何通过fullcalendar bootstrap的事件id获取和事件?
我有事件ID,我希望从中获取事件.我正在尝试这个:
var evento = $("#calendar").fullCalendar( 'clientEvents')[response.idEvent];
Run Code Online (Sandbox Code Playgroud)
response.idEvent是id事件,这是正确的(例如我的mysql数据库中的'32'),我知道这是因为我打印这个并且是正确的,但我不知道如何从这个获取事件...
怎么能得到这个?
谢谢!
我在swift中用AVFoundation录制视频,但是我没有看到file.mp4.我不知道我是否正在录音而且我保存不好或者我没有录音..因为我可以显示会话预览,所有组件都能正常运行..我的代码是:
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCaptureFileOutputRecordingDelegate {
var delegate : AVCaptureFileOutputRecordingDelegate?
@IBOutlet var imageView : UIImageView
@IBOutlet var imagePreview : UIView
var session : AVCaptureSession!
var fileOutput : AVCaptureMovieFileOutput!
var previewLayer : AVCaptureVideoPreviewLayer!
func initCamera() -> Bool {
var cameraBack : AVCaptureDevice?
var videoIn : AVCaptureDeviceInput
var devices : NSArray = AVCaptureDevice.devices()
for device: AnyObject in devices{
if device.position == AVCaptureDevicePosition.Back{
cameraBack = device as? AVCaptureDevice
}
}
delegate=self
var error : NSErrorPointer!
var deviceInput : AVCaptureInput …Run Code Online (Sandbox Code Playgroud) 我想在UIImageView中使用gif,但我不能.我的代码是:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"gif"];
UIImage *testImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
self.dataImageView.animationImages = testImage.images;
self.dataImageView.animationDuration = testImage.duration;
self.dataImageView.animationRepeatCount = 1;
self.dataImageView.image = testImage.images.lastObject;
[self.dataImageView startAnimating];
}
Run Code Online (Sandbox Code Playgroud)
迅速:
var url : NSURL = NSBundle.mainBundle().URLForResource("MAES", withExtension: "gif")
Run Code Online (Sandbox Code Playgroud)
在目标CI中有animatedImageWithAnimatedGIFData,但在swift中我不知道如何调用此或如果不存在..
谢谢!
UITablaView我的Objective C应用程序中有一个.我有自定义单元格标签和UIImageView.我想禁用部分行,以便didSelectRowAtIndexPath在用户单击此行的部分时禁用.
我要这个:
可能吗?
我需要保存在NSUserDefaults数组或其他数据结构中以使用以下格式保存对象:
name = "myName", lastName = "myLastName"
Run Code Online (Sandbox Code Playgroud)
我试图用一组数组来做这件事,但这无法保存NSUserDefaults.
现在我尝试使用具有结构的自定义类来创建对象并附加到数组,但在尝试将其保存到时也会出错NSUserDefaults.我需要保存这个结构,但我不知道什么是正确的形式.我该怎么做?
var taskMgr: TaskManager = TaskManager()
struct task {
var name = "Un-Named"
var lastName = "Un-lastNamed"
}
class TaskManager: NSObject {
var tasks : [task] = []
func addTask(name : String, lastName: String){
tasks.append(task(name: name, lastName: desc))
}
}
Run Code Online (Sandbox Code Playgroud) 我在 Xcode 中有一个包含一些目标的项目。当我打开故事板文件时,项目开始构建。这是一个缓慢的过程...
当我打开故事板时,如何停止这个构建过程?
谢谢!
我正在尝试在应用程序Swift中显示我的位置,但这没有显示任何内容,地图全是蓝色..
我的代码是这个形式的互联网教程:
var latitude:CLLocationDegrees = location.location.coordinate.latitude
var longitude:CLLocationDegrees = location.location.coordinate.longitude
var homeLati: CLLocationDegrees = 40.01540192
var homeLong: CLLocationDegrees = 20.87901079
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01
var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
var region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
self.mapKit.setRegion(region, animated: true)
self.mapKit.showsUserLocation = true
///Red Pin
var myHomePin = MKPointAnnotation()
myHomePin.coordinate = myHome
myHomePin.title = "Home"
myHomePin.subtitle = "Bogdan's home"
self.mapKit.addAnnotation(myHomePin)
Run Code Online (Sandbox Code Playgroud)
我在.split中导入了相应的配置..这段代码有什么不好的?
谢谢!
swift ×7
xcode6 ×4
avfoundation ×2
ios8 ×2
animation ×1
camera ×1
cllocation ×1
fullcalendar ×1
gif ×1
ios ×1
javascript ×1
jquery ×1
mapkit ×1
mysql ×1
objective-c ×1
storyboard ×1
uitableview ×1
xcode ×1
xcode7 ×1