我正在构建一个由本机iOS视图和反应原生屏幕组成的导航堆栈。但是,当我推送本机iOS视图时,视图布局不会像故事板中那样设计出来。我在Xcode中使用autolayout作为原生视图。
ICNativeViewManager.h
---------------------
#import <React/RCTViewManager.h>
@interface ICNativeViewManager : RCTViewManager
@end
ICNativeViewManager.m
---------------------
#import <React/RCTViewManager.h>
#import <React/RCTView.h>
#import "ICNativeViewManager.h"
@implementation ICNativeViewManager
UIViewController *vc;
RCT_EXPORT_MODULE()
-(UIView *)view
{
if (vc == nil)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"ICNativeUI" bundle:nil];
vc = [storyboard instantiateInitialViewController];
}
return vc.view;
}
RCT_EXPORT_VIEW_PROPERTY(labelText, NSString)
@end
答案 0 :(得分:0)
答案 1 :(得分:0)
我已设法使用带约束的容器视图来修复布局问题。点击按钮接收回调仍然有问题。
-(UIView *)view
{
UIView *parentView = [ICNativeView new];
parentView.translatesAutoresizingMaskIntoConstraints = NO;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"ICNativeUI" bundle:nil];
self.viewController = [storyboard instantiateInitialViewController];
UIView *nativeView = self.viewController.view;
[parentView addSubview:nativeView];
[parentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[nativeView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(nativeView)]];
[parentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[nativeView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(nativeView)]];
return parentView;
}