似乎Swift无法识别Objective-C-Header中的typedef,因为我得到以下错误:
无法从"MMDrawerControllerDrawerVisualStateBlock!"类型中找到用户定义的转换 输入'(MMDrawerController!,MMDrawerSide,CGFloat) - > Void'
我使用的是用Objective-C编写的MMDrawerController,我自己的代码虽然在Swift中.
typedef如下所示:
typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible);
Run Code Online (Sandbox Code Playgroud)
为清晰起见,这里有更多代码段:
AppDelegate.swift
func initDrawerController() {
drawerController = MMDrawerController(centerViewController: centerController, leftDrawerViewController: leftDrawerController, rightDrawerViewController: rightDrawerController)
drawerController?.setDrawerVisualStateBlock(MMDrawerVisualState.parallaxVisualStateBlockWithParallaxFactor(2.0))
}
Run Code Online (Sandbox Code Playgroud)
MMDrawerController.h
typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible);
@interface MMDrawerController : UIViewController
-(void)setDrawerVisualStateBlock:(void(^)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible))drawerVisualStateBlock;
@end
Run Code Online (Sandbox Code Playgroud)
MMDrawerVisualState.h
@interface MMDrawerVisualState : NSObject
+(MMDrawerControllerDrawerVisualStateBlock)parallaxVisualStateBlockWithParallaxFactor:(CGFloat)parallaxFactor;
@end
Run Code Online (Sandbox Code Playgroud)
模块桥接-Header.h
#import "MMDrawerController.h"
#import "MMDrawerVisualState.h"
Run Code Online (Sandbox Code Playgroud)
构建这个时,我的AppDelegate中出现了一个表达式错误setDrawerVisualStateBlock
,尽管在下面有一个typedef MMDrawerController.h
:
这是一个错误(因为在Objective-C上,它工作正常)?或者有谁知道/有想法如何处理它?非常感谢帮助,谢谢!
我已经在iOS应用程序中集成了MMDrawerController库,现在我需要恢复应用程序状态,即使应用程序在后台被杀死(仅当应用程序从前台输入到后台时),它在正常的导航应用程序中工作正常但是当我在我的应用程序中使用" setCenterViewController "选项更改导航,恢复无法按预期工作,并且我已按照此链接中提供的所有说明操作:" https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html "
我已经使用了setCenterViewController选项(推荐来自MMDrawer)导航到特定的屏幕,然后在后台删除应用程序,当我们重新打开它时会启动默认的初始屏幕,但我们期望它应该在进入背景之前重新打开屏幕.
这是代码片段:
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.homeController.navigationController.navigationBarHidden = YES;
HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *_navg = [[UINavigationController alloc]initWithRootViewController:homeVC];
_navg.restorationIdentifier = @"homeNavigationController";
homeVC.title = [self.dataSource objectAtIndex:indexPath.row]; homeVC.restorationIdentifier = @"HomeViewController";
[appDelegate.drawerController setCenterViewController:_navg withCloseAnimation:YES completion:nil];
self.currentViewController = _navg;
self.currentViewController.restorationIdentifier = @"homeNavigationController";
Run Code Online (Sandbox Code Playgroud)
帮我解决这个问题.
所以我最近遇到了这个非常整洁的库MMDrawerController.我已经设法安装它并使用appDelegate.m中的代码初始化它.
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIViewController * leftSideDrawerViewController = [[LeftViewController alloc] init];
UIViewController * centerViewController = [[CenterViewController alloc] init];
UIViewController * rightSideDrawerViewController = [[RightViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
[navigationController setRestorationIdentifier:@"MMExampleCenterNavigationControllerRestorationKey"];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController
rightDrawerViewController:rightSideDrawerViewController];
[self.drawerController setRestorationIdentifier:@"MMDrawer"];
[self.drawerController setMaximumRightDrawerWidth:200.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block){
block(drawerController, drawerSide, percentVisible);
}
}];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; …
Run Code Online (Sandbox Code Playgroud) 这是我的podfile:
platform :ios, '8.0'
use_frameworks!
target 'myApp' do
pod 'PureLayout', '~> 2.0.6'
pod 'MMDrawerController', '~> 0.5.7'
pod 'SwiftyJSON', '~> 2.2.0'
end
Run Code Online (Sandbox Code Playgroud)
这是我的标题:
#import <PureLayout/PureLayout.h>
#import <MMDrawerController/MMDrawerController.h>
#import <MMDrawerController/MMDrawerVisualState.h>
Run Code Online (Sandbox Code Playgroud)
当我设置此变量时var drawerController: MMDrawerController!
,我收到此错误:
Use of undeclared type 'MMDrawerController'
Run Code Online (Sandbox Code Playgroud)
我已经尝试删除所有的pod并运行pod install
,清除pod cache
并运行pod update
,但我仍然没有运气.任何帮助是极大的赞赏 :)
我必须对我的网桥标题做错了,因为我可以完全删除这些行:
#import <MMDrawerController/MMDrawerController.h>
#import <MMDrawerController/MMDrawerVisualState.h>
Run Code Online (Sandbox Code Playgroud)
只要我导入MMDrawerController
使用它的文件,程序就会正常运行.但是,这不起作用,反之亦然
我在我的项目中使用MMDrawerController.我有一个从左到右显示的菜单,它正常工作.但我的要求是有一个宽度为当前屏幕宽度的抽屉.我怎么能用Swift做到这一点?
目前屏幕看起来像这样,我需要让白色区域覆盖整个屏幕.
我MMDrawerController
用来显示抽屉.我的应用程序在单击抽屉菜单选项时崩溃.它在iOS9中运行良好,但在iOS8中崩溃.有没有人知道这里发生了什么.我在这里错过了什么吗?
当我点击左侧菜单栏选项时,我收到以下错误:
[UIScreenEdgePanGestureRecognizer视图]:发送到解除分配的实例0x155e6d9a0的消息
ios ×6
objective-c ×3
swift ×3
cocoapods ×1
drawer ×1
storyboard ×1
swift2 ×1
typedef ×1
uistoryboard ×1
xcode7 ×1