编辑:我认为它可能是关于从objective-c库加载.xib并在swift的视图控制器上显示它
我一直在尝试在快速应用中使用https://github.com/promet/PRAugmentedReality库。
下面你可以看到我将这个库集成到我的swift项目中的步骤,我的swift项目的代码以及objective-c和swift项目的下载链接。这里还有PR增强现实框架的YouTube视频:
链接1:Getting Started -> https://www.youtube.com/watch?v=fdN0XAoZXOY
链接2:Walkthrough of Internals-> https://www.youtube.com/watch?v=Xmx-0OnzTPY
Swift项目步骤:
然后我将头文件导入我的桥接文件(PRAR.h),就像这样
#import <PRAR/ARSettings.h>
#import <PRAR/PRARManager.h>
#import <PRAR/ARController.h>
#import <PRAR/ARObject.h>
#import <PRAR/ARRadar.h>
#import <PRAR/LocationMath.h>
为了在我的swift项目中运行此框架,其余的工作仍然在我的ViewController.swift文件中,例如:
import UIKit
import PRAR
var prARManager = PRARManager()
let x: Int32 = AR_VIEW_TAG
let y = Int(x)
class ViewController: UIViewController, PRARManagerDelegate{
func alert(title: String, withDetails details: String) {
print("alert function")
let alert: UIAlertView = UIAlertView(title: title, message: details, delegate: nil, cancelButtonTitle: "Ok", otherButtonTitles: "")
alert.show()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("1")
// AŞAĞIDAKİ SATIRDA BİR SORUN VAR!!!
prARManager = PRARManager.init(size: self.view.frame.size, delegate: self, showRadar: true)
print("2")
}
override func viewDidAppear(animated: Bool) {
print("3")
let locationCoordinates = CLLocationCoordinate2D(latitude: 41.085468, longitude: 29.044033)
print("4")
prARManager.startARWithData(self.getDummyData() as [AnyObject], forLocation: locationCoordinates)
print("5")
}
func getDummyData() -> NSArray {
print("6")
let dummyData: [AnyObject] = [["id": 0, "lat": 40.9780919, "lon": 27.511674, "title": "Tekirdağ"], ["id": 1, "lat": 40.8025157, "lon": 29.4397941, "title": "Gebze"]]
print("7")
return dummyData;
}
func prarDidSetupAR(arView: UIView, withCameraLayer cameraLayer: AVCaptureVideoPreviewLayer, andRadarView radar: UIView) {
print("8")
NSLog("Finished displaying ARObjects")
print("9")
self.view.layer.addSublayer(cameraLayer)
print("10")
self.view!.addSubview(arView)
print("11")
self.view.bringSubviewToFront(self.view.viewWithTag(y)!)
//self.view.bringSubviewToFront(self.view!.viewWithTag(AR_VIEW_TAG));
//self.view!.bringSubviewToFront(self.view!.viewWithTag( 042313 )!)
//print("12")
self.view.addSubview(radar)
//print("13")
}
func prarUpdateFrame(arViewFrame: CGRect) {
print("14")
self.view.viewWithTag(y)?.frame = arViewFrame
print("hello")
//self.view.viewWithTag(AR_VIEW_TAG)!.frame = arViewFrame
//self.view!.viewWithTag(042313)!.frame = arViewFrame
print("15")
}
func prarGotProblem(problemTitle: String!, withDetails problemDetails: String!) {
print("16")
self.alert(problemTitle, withDetails: problemDetails)
print("17")
}
}
您可以在下面下载objective-c和swift项目。我只是想让swift项目能够作为objective-c项目运行。我怎样才能做到这一点?我经常浏览所有框架和代码,但我看不出有什么问题。 * ps:我正在使用Xcode版本7.2.1
Swift项目的链接:https://drive.google.com/file/d/0B-cDfWHidgvcYnFNcnlMZG1aaDg/view?usp=sharing
Objective-C项目的链接:https://drive.google.com/file/d/0B-cDfWHidgvcQUFXbktYSE5CeHM/view?usp=sharing