ios - 在 UIView 子类中执行计算会破坏 MVC 的设计模式吗?

标签 ios objective-c model-view-controller uiview multi-touch

我有一个 UIView 子类,我在其中覆盖了多点触控处理方法。我的问题是,如果我在该 View 上使用给定的触摸执行计算,它会破坏 Model View Controller 设计模式吗?。计算完成后,我必须隐藏 View 、打印结果并更新我的核心数据模型。我对此感到困惑。

编辑:

一些代码。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // getting all the touches in the given gesture sequence
    NSSet *allTouches = [event allTouches];

    // checking taps count
    if ([allTouches count] == 3)
    {
        // here I print the results and do the calculations
        [self validateGestureSequenceWithTouches:allTouches];
    }

    // cleaning the view
    NSArray *subviews = [self subviews];
    for (UIView *view in subviews) {
       if (![view isKindOfClass:[UINavigationBar class]])
           [view removeFromSuperview];
    }
}

最佳答案

为了遵守 MVC 准则,您的业务级计算需要在您的模型层中进行。然而,并非所有计算都符合“业务计算”的条件:很多时候您必须执行计算来决定 UI 事项,例如

  • 单个 UI 元素的可见性
  • 单个 ui 元素的大小,
  • 触摸的位置和方向,

等等。如果您的计算属于业务类型,则应将其移至模型中。否则,最好将其保留在 View 或 Controller 中。

关于ios - 在 UIView 子类中执行计算会破坏 MVC 的设计模式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15694614/

相关文章:

ios - 实时更改 View 渐变背景

ios - 使用 .xib 文件在 Swift 中加载导航栏

ios - remotebuild 无法在 iphone 6 设备上部署 cordova 应用程序 - iphone 5 设备工作正常

java - 在运行时添加监听器? -Java MVC

ruby-on-rails - ruby on Rails 中的路由是 MVC Controller 的一部分吗?

ios - 如何从 UIImagePickerController 检索 PHAsset

ios - 更改tableview中滚动条的颜色

ios - 如何以编程方式获取 iphone 的 MAC 地址

objective-c - 在 UICollectionView 中处理点击手势

jquery - 在 View 中渲染 JSON 数据 - play 框架