weex总结(iOS集成weex)

2018-05-06  本文已影响186人  拥抱月亮的大星星

1.<image>标签使用本地图片

在 iOS 中,Weex 会在 bundle resources 【根目录建个resources文件夹,放入本地图片】中查找。例如,
image 组件的 src 属性为 local:///app_icon', Weex 会加载
 bundle resouce 中名为 app_icon 的图像资源,而字体文件也
以相同的方式工作。

2.<image> src 网络图片不显示问题

//初始化weex
[WXSDKEngine initSDKEnvironment];

//下载图片(自己实现这个协议则可显示下载图片,weex已实现)
[WXSDKEngine registerHandler:[WXImgLoaderDefaultImpl new] withProtocol:@protocol(WXImgLoaderProtocol)];

3.weex 调用 oc

比如 weex要调用oc里面的某个方法或者跳转到某个界面

扩展 iOS 的功能

4.已有项目扩展weex功能

1.跳转跳转界面(如WTestViewController.h)


#import <UIKit/UIKit.h>

@interface WTestViewController : UIViewController
@property (nonatomic, strong) NSString *url;
@end



#import "WTestViewController.h"
#import <WeexSDK/WXSDKInstance.h>




@interface WTestViewController ()
@property (nonatomic, strong) WXSDKInstance *instance;
@property (nonatomic, strong) UIView *weexView;
@end

@implementation WTestViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _instance = [[WXSDKInstance alloc] init];
    _instance.viewController = self;
    _instance.frame = self.view.frame;
    
    __weak typeof(self) weakSelf = self;
    _instance.onCreate = ^(UIView *view) {
        [weakSelf.weexView removeFromSuperview];
        weakSelf.weexView = view;
        [weakSelf.view addSubview:weakSelf.weexView];
    };
    
    _instance.onFailed = ^(NSError *error) {
        //process failure
    };
    
    _instance.renderFinish = ^ (UIView *view) {
        //process renderFinish
    };
    
//    
    
    
    
    [_instance renderWithURL:[NSURL URLWithString:self.url] options:@{@"bundleUrl":self.url} data:nil];
    //    [_instance renderWithURL:[NSURL URLWithString:@"http://10.83.4.85/weexNative-h5/index.js"] options:nil data:nil];
    
//    NSURL *url = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"js"];
//    [_instance renderWithURL:url options:@{@"bundleUrl":[self.url absoluteString]} data:nil];
}

- (void)dealloc
{
    [_instance destroyInstance];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

2.在根目录添加bundlejs目录,里面存放生成好的js

../bundlejs/index.js

疑问待解决

1.步骤4中是本地js,实际项目是否是把生成的index.js文件放在服务器上?

2.在原生界面不同的地方,如果调不同的weex界面

3.导航条一般怎么处理

4.待续...

上一篇 下一篇

猜你喜欢

热点阅读