# MVVM+RAC
**采用MVVM设计模式**
[博客链接](http://www.jianshu.com/p/84ce914f22ac)
####前言
本项目的数据为抓包所得,并且都是用的本地数据,只作为学习用途。**项目中所用到的appKey,为了方便调试,不再删除!但是仅作为本项目使用!**
写这个项目之前也是对MVVM及RAC了解止于博客之类,写之前花了几天动手写了RAC的一些demo,然后才正式开始的项目,如果对RAC一点不了解的话,建议先看看RAC及FRP(函数响应式编程),然后再看本项目。[RACdemo](https://github.com/wangtongke/WTKRacDemo.git)。
![首页](http://upload-images.jianshu.io/upload_images/2455861-68e3709d61e0ba99.gif?imageMogr2/auto-orient/strip)
![搜索](http://upload-images.jianshu.io/upload_images/2455861-42824a76fc121a38.gif?imageMogr2/auto-orient/strip)
![订单](http://upload-images.jianshu.io/upload_images/2455861-da450e798cbbe7c9.gif?imageMogr2/auto-orient/strip)
![分享](http://upload-images.jianshu.io/upload_images/2455861-4f9a069f647b25f7.gif?imageMogr2/auto-orient/strip)
![分类](http://upload-images.jianshu.io/upload_images/2455861-e437e2fda96caf8e.gif?imageMogr2/auto-orient/strip)
![购物车](http://upload-images.jianshu.io/upload_images/2455861-bfaba29b40f7bc36.gif?imageMogr2/auto-orient/strip)
![指纹支付](http://upload-images.jianshu.io/upload_images/2455861-f08d595e4c8a97c1.gif?imageMogr2/auto-orient/strip)
####关于RAC及MVVM
* RAC-函数响应式编程(FRP)的一个重量级的库,学习难度较为陡峭,不过极大的简化代码,统一了消息传递机制。另外就是性能较原生的有一定的差距,当然,硬件的提升这些差距基本上会感觉不到。
* MVVM-不管是MVVM还是MVP、VIEPR或者MV(X),用意皆在使代码结构清晰、易于维护、易于测试。另外不管是MVC还是MVVM,都有两种情况,1、整个项目一个大的MVC。2、每个模块都有自己的MVC,比如首页的MVC,我的页面的MVC。各有有点吧。
**这两点不再赘述,适合自己的、自己熟悉的才是最好用的**, **另外,新的设计模式会使调试、debug的时间增加很多**
####pod
使用的第三方不多,除了RAC都是一般项目都有的
```
use_frameworks!
platform :ios, ‘8.0’
target “WTKWineMVVM” do
pod 'ReactiveCocoa', '4.2.2'
pod 'AFNetworking', '~> 3.1.0'
pod 'SVProgressHUD', '~> 2.0.3'
pod 'SDWebImage' , '3.7.3'
pod 'Masonry'
pod 'MJRefresh', '~> 3.1.12'
pod 'DZNEmptyDataSet', '~> 1.8.1'
pod 'Reachability', '~> 3.2'
pod 'MJExtension', '~> 3.0.13'
end
```
####Common
![common](http://upload-images.jianshu.io/upload_images/2455861-8d5d7dc6ddfa17ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
wtk开头的几个是我开发中封装的,这个建议开发中多思考,看那些是可以复用的(或者其他项目可以复用的),都尽量封装起来,方便以后使用。
* WTKQRCode 二维码扫描的,使用的系统的API,已经封装好,[QRCode连接](https://github.com/wangtongke/WTKQRCode.git)。
* WTKStar 星级评价的view,可以支持触摸修改、整形浮点型两种,[WTKStar连接](https://github.com/wangtongke/WTKStarView.git)
* WTKDropView 带动画下拉列表,项目中有两处用到,一个是还第一次写的,没有封装好,第二次时封装了一下,所以还是建议多封装,避免重复写一样的代码。[WTKDropView连接](https://github.com/wangtongke/WTKDropView.git)
* WTKTransition 转场动画,项目中的push、pop动画都是圆形扩散的,项目中用的也是还没有封装好的,需要借助basedViewController来实现,后来封装了一个,两行代码可以实现。使用中,如果某界面有手势与pop手势冲突,把pop手势从view上删除即可。[WTKTransition连接](https://github.com/wangtongke/WTKTransitionAnimate.git)
####Based
这里面包括了`tabbarController、navigationController、basedViewController、basedViewModel、viewModelServices、viewModelNavigationImpl`
#####tabbarController
tabbarController主要有添加子控制器、广告页、监听badgeValue、读取本地数据、自定义切换动画,
* 切换动画
![切换动画.gif](http://upload-images.jianshu.io/upload_images/2455861-fbfa35844d68fba8.gif?imageMogr2/auto-orient/strip)
```
- (void)beginAnimation
{
CATransition *animation = [[CATransition alloc]init];
animation.duration = 0.5;
animation.type = kCATransitionFade;
animation.subtype = kCATransitionFromRight;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
animation.accessibilityFrame = CGRectMake(0, 64, kWidth, kHeight);
[self.view.layer addAnimation:animation forKey:@"switchView"];
}
```
* 监听bageValue
实际上就是监听购物车的总数(单例类的一个属性),然后设置下标,这里使用RACObserver代替KVO实现。
```
@weakify(self);
[RACObserve([WTKUser currentUser], bageValue) subscribeNext:^(id x) {
@strongify(self);
UIViewController *vc = self.viewControllers[3];
NSInteger num = [x integerValue];
dispatch_async(dispatch_get_main_queue(), ^{
if (num > 0)
{
[vc.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld",num]];
}
else
{
[vc.tabBarItem setBadgeValue:nil];
}
});
}];
```
#####navigationController
一般项目中,只有一级界面显示tabbar,所以有许多地方push的时候都会隐藏,所以在navigation中,可以实现push方法,然后隐藏,其他地方都不用再处理
```
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.viewControllers.count > 0)
{
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}
```
另外navigation还有转场动画相关的代理,不再多说。
##### BasedViewController
basedVC主要是配置一些通用的东西,比如属性viewModel、背景色、返回按钮以及MVVM的核心Bind(绑定)方法。使用basedVC的好处就是一处配置,整个项目通用。
```
if (self.navigationController && self != self.navigationController.viewControllers.firstObject)
{
[self resetNaviWithTitle:@""];
UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePopRecognizer:)];
[self.view addGestureRecognizer:popRecognizer];
popRecognizer.delegate = self;
}
```
如果不是一级页面,则会自动添加返回按钮。
bindViewModel
```
- (void)bindViewModel
{
RAC(self.navigationItem,title) = RACObserve(self.viewModel, title);
}
```
这里只是完成了title的绑定,因为每次push的都是viewModel而不是viewController,所以viewModel也声明了一个title的属性。
#####basedViewModel
主要是实现了构建方法、登录相关。
```
- (instancetype)initWithService:(id<WTKViewModelServices>)service params:(NSDictionary *)params
{
self = [super init];
if (self)
{
self.title = params[@"title"];
self.params = params;
self.services = service;
}
return self;
}
```
每次创建需要传一个service和param,service用来push,不过这个项目一开始并没有用这个,所以比较遗憾。param用来传值,title必须有!!。
#####WTKViewModelServices协议
协议,协议方法为push、pop等,
```
- (void)pushViewModel:(WTKBasedViewModel *)viewModel animated:(BOOL)animated;
- (void)popViewControllerWithAnimation:(BOOL)animated;
没有合适的资源?快使用搜索试试~ 我知道了~
高仿电商项目,采用MVVM+ReactiveCocoa-WTKMVVMRAC.zip
共1507个文件
h:527个
m:325个
png:295个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 88 浏览量
2024-01-29
21:06:04
上传
评论
收藏 55.88MB ZIP 举报
温馨提示
高仿电商项目,采用MVVM+ReactiveCocoa-WTKMVVMRAC
资源推荐
资源详情
资源评论
收起资源包目录
高仿电商项目,采用MVVM+ReactiveCocoa-WTKMVVMRAC.zip (1507个子文件)
ios_open_sdk_3.1.0.3_iphone 0B
libWeiboSDK.a 24.14MB
libWeChatSDK.a 10.4MB
libAPOpenSdk.a 1.26MB
all-wcprops 2KB
AllComment 4KB
AllOrder 31KB
BadComment 762B
BaiduMapAPI_Base 8.55MB
BaiduMapAPI_Cloud 984KB
BaiduMapAPI_Location 201KB
BaiduMapAPI_Map 23.98MB
BaiduMapAPI_Radar 709KB
BaiduMapAPI_Search 9.68MB
BaiduMapAPI_Utils 2.24MB
CategoryAllGoods 298KB
CategorySiftAll 64KB
mfp.cer 577B
DVDirectory.cfg 68KB
DVDirectory_Retina.cfg 68KB
DVHotMap.cfg 11KB
DVHotMap_Retina.cfg 11KB
DVIndoor.cfg 11KB
DVSDirectory_Retina.cfg 5KB
DVSDirectory.cfg 5KB
DVHotcity.cfg 2KB
DVHotcity_Retina.cfg 2KB
DVVersion_Retina.cfg 349B
DVVersion.cfg 341B
channel 5B
countryList 826B
Current 1B
CustomIndex 4KB
RACSignalProvider.d 222B
RACCompoundDisposableProvider.d 190B
DeliveryOrder 0B
entries 2KB
entries 551B
FinishDeliveryOrder 0B
FinishOrder 13KB
line@2x.gif 43B
GoodComment 4KB
BMKVersion.h 50KB
NSMutableDictionary+SSDKShare.h 37KB
RACSignal+Operations.h 32KB
RACmetamacros.h 30KB
AFURLSessionManager.h 29KB
BMKMapView.h 24KB
TencentOAuth.h 23KB
WXApiObject.h 22KB
AFURLRequestSerialization.h 22KB
WeiboSDK.h 21KB
QQApiInterfaceObject.h 20KB
WBHttpRequest+WeiboUser.h 20KB
BMKRouteSearchType.h 20KB
AFHTTPSessionManager.h 19KB
IQUIView+IQKeyboardToolbar.h 15KB
TencentOAuthObject.h 14KB
BMKGeometry.h 13KB
RACStream.h 13KB
UIButton+WebCache.h 13KB
AFURLResponseSerialization.h 12KB
MobClick.h 12KB
sdkdef.h 11KB
SDWebImageManager.h 11KB
UIScrollView+EmptyDataSet.h 11KB
NSObject+MJKeyValue.h 10KB
NSMutableDictionary+SSDKInit.h 10KB
UIButton+AFNetworking.h 10KB
UIImageView+WebCache.h 10KB
IQKeyboardManager.h 10KB
RACSignal.h 9KB
SSDKTypeDefine.h 9KB
TencentMessageObject.h 9KB
SVProgressHUD.h 9KB
AFImageDownloader.h 9KB
IQKeyboardManagerConstants.h 8KB
SDImageCache.h 8KB
AFNetworkReachabilityManager.h 8KB
BMKOverlayView.h 8KB
BMKPoiSearchType.h 7KB
MASConstraint.h 7KB
WBHttpRequest+WeiboGame.h 7KB
RACScheduler.h 7KB
SDWebImageDownloader.h 7KB
BMKTypes.h 6KB
MOBFBigInteger.h 6KB
RACSequence.h 6KB
MASUtilities.h 6KB
UIImageView+AFNetworking.h 6KB
AFSecurityPolicy.h 6KB
AFAutoPurgingImageCache.h 6KB
WBHttpRequest.h 6KB
MASConstraintMaker.h 5KB
RACTuple.h 5KB
WXApi.h 5KB
AFNetworkActivityIndicatorManager.h 5KB
ShareSDK+Base.h 5KB
RACCommand.h 5KB
NSObject+RACPropertySubscribing.h 5KB
共 1507 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
资源评论
武昌库里写JAVA
- 粉丝: 3525
- 资源: 2059
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功