UI与数据分离 与 UI的演进

Posted zzfx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UI与数据分离 与 UI的演进相关的知识,希望对你有一定的参考价值。

解藕的好处:UI内部模块能够灵活的变化。

 

MVC或者三层架构着重强调了数据、业务逻辑和UI的分离。

(MVC中的C只是UI和业务逻辑模块间的一个中转组件,理论上应该是个轻模块。)

 

以前的关注的解藕技术比耦合多;重点强调了现实与数据、业务逻辑的解藕;现实与数据的耦合则很少关注。

 

UI展示的主要工作:内容、样式、布局。

 

视图的分类:

简单视图:单一信息源视图;uilabel、uiiamgeview

符合视图:数据源为结构体;

 

数据源类型:

可配置;

不可配置;

 

UI布局的定制需求:需要开放接口给外面。

 

 

View开发定式:

1)配置子视图;loadSbuviews configSubviews

2)配置布局;  自动布局  layoutsubviews;

3)配置数据;      loadDatas; 如果使用自动布局,配置数据后不用进行二次布局;否则需要二次布局。

 

 

数据配置与在MVC中的位置。

 

数据配置接口是视图层与业务逻辑层的接口。

理论上只有与业务逻辑有关的视图需要有这个接口。

 

UI的大部分功能还是信息展示和用户交互。

 

系统UI的支持(UIView):

事件处理:UIView : UIResponder 

视图布局UIView(UIViewGeometry)

  UIView (UIConstraintBasedLayoutCoreMethods) 

视图组合:UIView(UIViewHierarchy)

视图样式(渲染):(UIViewRendering)

 

系统UI的数据接口支持(uilabel):

数据: @property(nullable, nonatomic,copy)   NSString           *text;    

样式: @property(null_resettable, nonatomic,strong) UIFont      *font;  

@property(null_resettable, nonatomic,strong) UIColor     *textColor;

@property(nullable, nonatomic,strong) UIColor            *shadowColor;

@property(nonatomic)        CGSize             shadowOffset;    

 

 

MVC中的C:主要工作是UI导航。

 

 

https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW6

 

Checklist for Implementing a Custom View

The job of a custom view is to present content and manage interactions with that content. The successful implementation of a custom view involves more than just drawing and handling events, though. The following checklist includes the more important methods you can override (and behaviors you can provide) when implementing a custom view:

 

 

  • Define the appropriate initialization methods for your view:
    • For views you plan to create programmatically, override the initWithFrame: method or define a custom initialization method.
    • For views you plan to load from nib files, override the initWithCoder: method. Use this method to initialize your view and put it into a known state.
  • Implement a dealloc method to handle the cleanup of any custom data.
  • To handle any custom drawing, override the drawRect: method and do your drawing there.
  • Set the autoresizingMask property of the view to define its autoresizing behavior.
  • If your view class manages one or more integral subviews, do the following:
    • Create those subviews during your view’s initialization sequence.
    • Set the autoresizingMask property of each subview at creation time.
    • If your subviews require custom layout, override the layoutSubviews method and implement your layout code there.

 

 

 

 

 

 

 

https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW6

Views

Because view objects are the main way your application interacts with the user, they have many responsibilities. Here are just a few:

  • Layout and subview management
    • A view defines its own default resizing behaviors in relation to its parent view.
    • A view can manage a list of subviews.
    • A view can override the size and position of its subviews as needed.
    • A view can convert points in its coordinate system to the coordinate systems of other views or the window.
  • Drawing and animation
    • A view draws content in its rectangular area.
    • Some view properties can be animated to new values.
  • Event handling
    • A view can receive touch events.
    • A view participates in the responder chain.

This chapter focuses on the steps for creating, managing, and drawing views and for handling the layout and management of view hierarchies. For information about how to handle touch events (and other events) in your views, see Event Handling Guide for UIKit Apps.

 

以上是关于UI与数据分离 与 UI的演进的主要内容,如果未能解决你的问题,请参考以下文章

大型网站架构演进数据库与应用服务器分离

大型网站架构演进数据库与应用服务器分离

大型网站架构系列

分布式 - 分布式体系架构:IT架构的演进过程

与“十“俱进 阿里数据库运维10年演进之路

服务端搭建高并发分布式架构演进之路