我正在尝试为我正在使用的App设计条形码扫描仪.我希望扫描仪预览能够填满设备的整个屏幕,并提供一个较小的框架来指向条形码.所有的工作都是我想要的,但我不能让感兴趣的框架工作.
这是条形码扫描仪的实现:
#import "GEScannerViewController.h"
@import AVFoundation;
@interface GEScannerViewController () <AVCaptureMetadataOutputObjectsDelegate> {
AVCaptureSession *_session;
AVCaptureDevice *_device;
AVCaptureDeviceInput *_input;
AVCaptureMetadataOutput *_output;
AVCaptureVideoPreviewLayer *_prevLayer;
UIView *_greyView;
UIView *_highlightView;
UIView *_scopeView;
UILabel *_label;
}
@end
@implementation GEScannerViewController
- (void)viewDidLoad {
[super viewDidLoad];
_label = [[UILabel alloc] init];
_label.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40);
_label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
_label.backgroundColor = [UIColor colorWithWhite:0.15 alpha:0.65];
_label.textColor = [UIColor whiteColor];
_label.textAlignment = NSTextAlignmentCenter;
_label.text = @"(none)";
[self.view addSubview:_label];
NSError *error = nil;
_session = [[AVCaptureSession alloc] init]; …Run Code Online (Sandbox Code Playgroud) 我有一个简单的应用程序,用于测试其余api的推送通知。我想在应用程序中显示导航栏,但是它不起作用。在我的AppDelegate中,我有以下代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.registerForPushNotifications()
let url = "dev"
UserDefaults.standard.setValue(FFHelper.url(slug: url.slug()), forKey: "api-url")
var vcString = "loginView"
if KeychainSwift().get("auth-token") != nil {
vcString = "notificationsTable"
}
let initialVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: vcString)
initialVC.navigationController?.navigationBar.isHidden = false
initialVC.navigationController?.setNavigationBarHidden(false, animated: true)
window?.rootViewController = initialVC
window?.makeKeyAndVisible()
return true
}
Run Code Online (Sandbox Code Playgroud)
在情节提要中,导航栏也已启用:
最后,在viewController中,我做同样的事情:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationController?.navigationBar.isHidden = false
super.viewWillAppear(animated)
}
Run Code Online (Sandbox Code Playgroud)