IOS 自动布局更改旋转位置

2023-12-12

我想将一个容器发送到另一个容器的下方,纵向发送,横向发送并排。仅使用自动布局可以吗?我知道我可以通过编程来做到这一点,只是想知道是否可以从布局中做到这一点。

像这样:

Desired Behaviour


Well didRotateFromInterfaceOrientation不是使用 iOS 8 执行此类操作的首选方法。我建议您查看一下 TraitCollection 和与其关联的视图控制器方法。这里的技巧是安装水平约束或垂直约束UI视图控制器 method viewWillTransitionToSize:withTransitionCoordinator: 扳机。

这是我的做法,

@interface ViewController ()

@property (nonatomic, weak) UIView *aContainerView;
@property (nonatomic, weak) UIView *bContainerView;

@property (nonatomic, strong) NSArray *horizontalOrientationConstraints;
@property (nonatomic, strong) NSArray *verticalOrientationConstraints;

@end

@implementation ViewController

#pragma mark - Getters

- (NSArray *)horizontalOrientationConstraints
{
    if (!_horizontalOrientationConstraints) {
        NSLayoutConstraint *equalWidthConstraints = [NSLayoutConstraint constraintWithItem:self.aContainerView
                                                                                 attribute:NSLayoutAttributeWidth
                                                                                 relatedBy:NSLayoutRelationEqual
                                                                                    toItem:self.bContainerView
                                                                                 attribute:NSLayoutAttributeWidth
                                                                                multiplier:1.0
                                                                                  constant:0];

        NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[aContainerView][bContainerView]|"
                                                                        options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom
                                                                        metrics:nil views:@{@"aContainerView": self.aContainerView, @"bContainerView": self.bContainerView}];
        NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[aContainerView]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:@{@"aContainerView": self.aContainerView}];
        NSArray *constraints = [vConstraints arrayByAddingObjectsFromArray:hConstraints];
        _horizontalOrientationConstraints = [constraints arrayByAddingObject:equalWidthConstraints];

    }
    return _horizontalOrientationConstraints;
}


- (NSArray *)verticalOrientationConstraints
{
    if (!_verticalOrientationConstraints) {
        NSLayoutConstraint *equalHeightConstraints = [NSLayoutConstraint constraintWithItem:self.aContainerView
                                                                                  attribute:NSLayoutAttributeHeight
                                                                                  relatedBy:NSLayoutRelationEqual
                                                                                     toItem:self.bContainerView
                                                                                  attribute:NSLayoutAttributeHeight
                                                                                 multiplier:1.0
                                                                                   constant:0];


        NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[aContainerView][bContainerView]|"
                                                                        options:NSLayoutFormatAlignAllLeft | NSLayoutFormatAlignAllRight
                                                                        metrics:nil views:@{@"aContainerView": self.aContainerView, @"bContainerView": self.bContainerView}];
        NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[aContainerView]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:@{@"aContainerView": self.aContainerView}];
        NSArray *constraints = [vConstraints arrayByAddingObjectsFromArray:hConstraints];
        _verticalOrientationConstraints = [constraints arrayByAddingObject:equalHeightConstraints];

    }
    return _verticalOrientationConstraints;
}

#pragma mark - 


- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView *aContainerView = [self viewWithLabelText:@"A" andBackgroundColor:[UIColor yellowColor]];
    UIView *bContainerView = [self viewWithLabelText:@"B" andBackgroundColor:[UIColor greenColor]];

    [self.view addSubview:aContainerView];
    [self.view addSubview:bContainerView];

    self.aContainerView = aContainerView;
    self.bContainerView = bContainerView;

    CGSize viewSize = self.view.bounds.size;

    if (viewSize.width > viewSize.height) {
        [NSLayoutConstraint activateConstraints:self.horizontalOrientationConstraints];
    } else {
        [NSLayoutConstraint activateConstraints:self.verticalOrientationConstraints];
    }
}

- (UIView *)viewWithLabelText:(NSString *)text andBackgroundColor:(UIColor *)color
{
    UIView *aContainerView = [[UIView alloc] init];
    aContainerView.backgroundColor = [UIColor blackColor];
    aContainerView.translatesAutoresizingMaskIntoConstraints = NO;

    UIView *aView = [[UIView alloc] init];
    aView.translatesAutoresizingMaskIntoConstraints = NO;
    aView.backgroundColor = color;

    UILabel *aLabel = [[UILabel alloc] init];
    aLabel.translatesAutoresizingMaskIntoConstraints = NO;
    aLabel.text = text;
    aLabel.font = [UIFont systemFontOfSize:80];

    [aView addSubview:aLabel];

    [aContainerView addSubview:aView];


    NSLayoutConstraint *centerXConstraints = [NSLayoutConstraint constraintWithItem:aView
                                                                          attribute:NSLayoutAttributeCenterX
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:aLabel
                                                                          attribute:NSLayoutAttributeCenterX
                                                                         multiplier:1.0
                                                                           constant:0];
    NSLayoutConstraint *centerYConstraints = [NSLayoutConstraint constraintWithItem:aView
                                                                          attribute:NSLayoutAttributeCenterY
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:aLabel
                                                                          attribute:NSLayoutAttributeCenterY
                                                                         multiplier:1.0
                                                                           constant:0];
    [aContainerView addConstraints:@[centerXConstraints, centerYConstraints]];


    NSString *hConstraintsFormat = @"V:|-10-[view]-10-|";
    NSString *vConstraintsFormat = @"H:|-10-[view]-10-|";

    [aContainerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:hConstraintsFormat
                                                                                options:0
                                                                                metrics:nil
                                                                                  views:@{@"view": aView}]];
    [aContainerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:vConstraintsFormat
                                                                                options:0
                                                                                metrics:nil
                                                                                  views:@{@"view": aView}]];

    return aContainerView;
}



 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    NSArray *constraintsToDeactivate;
    NSArray *constraintsToActivate;

    if (size.width > size.height) {
        constraintsToActivate = self.horizontalOrientationConstraints;
        constraintsToDeactivate = self.verticalOrientationConstraints;
    } else {
        constraintsToActivate = self.verticalOrientationConstraints;
        constraintsToDeactivate = self.horizontalOrientationConstraints;
    }

    [NSLayoutConstraint deactivateConstraints:constraintsToDeactivate];
    [NSLayoutConstraint activateConstraints:constraintsToActivate];
    [self.view layoutIfNeeded];
}

@end

这是两个方向的外观,

enter image description here

enter image description here

对于iOS7,你基本上做同样的事情。与其重写 viewWillTransitionToSize: ,不如重写 willAnimateRotationToInterfaceOrientation:duration: 。然后您在方法内添加或删除约束,

@interface ViewController ()

@property (nonatomic, weak) UIView *aContainerView;
@property (nonatomic, weak) UIView *bContainerView;

@property (nonatomic, assign) BOOL touchExited;
@property (nonatomic, assign) NSUInteger count;
@property (nonatomic, weak) NSTimer *countChangeTimer;
@property (nonatomic, weak) UIButton *theCountButton;

@property (nonatomic, strong) NSArray *horizontalOrientationConstraints;
@property (nonatomic, strong) NSArray *verticalOrientationConstraints;

@end

@implementation ViewController

#pragma mark - Getters

- (NSArray *)horizontalOrientationConstraints
{
    if (!_horizontalOrientationConstraints) {
        NSLayoutConstraint *equalWidthConstraints = [NSLayoutConstraint constraintWithItem:self.aContainerView
                                                                                 attribute:NSLayoutAttributeWidth
                                                                                 relatedBy:NSLayoutRelationEqual
                                                                                    toItem:self.bContainerView
                                                                                 attribute:NSLayoutAttributeWidth
                                                                                multiplier:1.0
                                                                                  constant:0];

        NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[aContainerView][bContainerView]|"
                                                                        options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom
                                                                        metrics:nil views:@{@"aContainerView": self.aContainerView, @"bContainerView": self.bContainerView}];
        NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[aContainerView]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:@{@"aContainerView": self.aContainerView}];
        NSArray *constraints = [vConstraints arrayByAddingObjectsFromArray:hConstraints];
        _horizontalOrientationConstraints = [constraints arrayByAddingObject:equalWidthConstraints];

    }
    return _horizontalOrientationConstraints;
}


- (NSArray *)verticalOrientationConstraints
{
    if (!_verticalOrientationConstraints) {
        NSLayoutConstraint *equalHeightConstraints = [NSLayoutConstraint constraintWithItem:self.aContainerView
                                                                                  attribute:NSLayoutAttributeHeight
                                                                                  relatedBy:NSLayoutRelationEqual
                                                                                     toItem:self.bContainerView
                                                                                  attribute:NSLayoutAttributeHeight
                                                                                 multiplier:1.0
                                                                                   constant:0];


        NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[aContainerView][bContainerView]|"
                                                                        options:NSLayoutFormatAlignAllLeft | NSLayoutFormatAlignAllRight
                                                                        metrics:nil views:@{@"aContainerView": self.aContainerView, @"bContainerView": self.bContainerView}];
        NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[aContainerView]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:@{@"aContainerView": self.aContainerView}];
        NSArray *constraints = [vConstraints arrayByAddingObjectsFromArray:hConstraints];
        _verticalOrientationConstraints = [constraints arrayByAddingObject:equalHeightConstraints];

    }
    return _verticalOrientationConstraints;
}

#pragma mark -

- (void)invalidateTimer
{
    if (self.countChangeTimer) {
        [self.countChangeTimer invalidate];
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView *aContainerView = [self viewWithLabelText:@"A" andBackgroundColor:[UIColor yellowColor]];
    UIView *bContainerView = [self viewWithLabelText:@"B" andBackgroundColor:[UIColor greenColor]];

    [self.view addSubview:aContainerView];
    [self.view addSubview:bContainerView];
    self.aContainerView = aContainerView;
    self.bContainerView = bContainerView;

    CGSize viewSize = self.view.bounds.size;

    if (viewSize.width > viewSize.height) {
        [self.view addConstraints:self.horizontalOrientationConstraints];
    } else {
        [self.view addConstraints:self.verticalOrientationConstraints];
    }
}

- (UIView *)viewWithLabelText:(NSString *)text andBackgroundColor:(UIColor *)color
{
    UIView *aContainerView = [[UIView alloc] init];
    aContainerView.backgroundColor = [UIColor blackColor];
    aContainerView.translatesAutoresizingMaskIntoConstraints = NO;

    UIView *aView = [[UIView alloc] init];
    aView.translatesAutoresizingMaskIntoConstraints = NO;
    aView.backgroundColor = color;

    UILabel *aLabel = [[UILabel alloc] init];
    aLabel.translatesAutoresizingMaskIntoConstraints = NO;
    aLabel.text = text;
    aLabel.font = [UIFont systemFontOfSize:80];

    [aView addSubview:aLabel];

    [aContainerView addSubview:aView];


    NSLayoutConstraint *centerXConstraints = [NSLayoutConstraint constraintWithItem:aView
                                                                          attribute:NSLayoutAttributeCenterX
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:aLabel
                                                                          attribute:NSLayoutAttributeCenterX
                                                                         multiplier:1.0
                                                                           constant:0];
    NSLayoutConstraint *centerYConstraints = [NSLayoutConstraint constraintWithItem:aView
                                                                          attribute:NSLayoutAttributeCenterY
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:aLabel
                                                                          attribute:NSLayoutAttributeCenterY
                                                                         multiplier:1.0
                                                                           constant:0];
    [aContainerView addConstraints:@[centerXConstraints, centerYConstraints]];


    NSString *hConstraintsFormat = @"V:|-10-[view]-10-|";
    NSString *vConstraintsFormat = @"H:|-10-[view]-10-|";

    [aContainerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:hConstraintsFormat
                                                                                options:0
                                                                                metrics:nil
                                                                                  views:@{@"view": aView}]];
    [aContainerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:vConstraintsFormat
                                                                                options:0
                                                                                metrics:nil
                                                                                  views:@{@"view": aView}]];

    return aContainerView;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration{
    NSArray *constraintsToDeactivate;
    NSArray *constraintsToActivate;

        if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            constraintsToActivate = self.horizontalOrientationConstraints;
            constraintsToDeactivate = self.verticalOrientationConstraints;
        } else {
            constraintsToActivate = self.verticalOrientationConstraints;
            constraintsToDeactivate = self.horizontalOrientationConstraints;
        }
        [self.view removeConstraints:constraintsToDeactivate];
        [self.view addConstraints:constraintsToActivate];

}

@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

IOS 自动布局更改旋转位置 的相关文章

  • NSCF 数组越界?

    我有一个相当简单的应用程序 使用 Core Data 和几个数组控制器 在 IB 中 除了 xcdatamodel 文件之外 没有它们的代码文件 当我运行应用程序时 我在日志中收到以下错误 应用程序仍然运行 但在转到 文件 gt 新文档 之
  • 用于测试对象类型的通用 Swift 函数

    我正在尝试编写一个函数 该函数接受一个对象和一个类型作为参数 并返回一个布尔值 指示该对象是否属于给定类型 似乎没有 Type 类型 所以我不知道如何做到这一点 我能做的最好的就是 func objectIsType
  • 在文件输入上反应 PWA IOS/Safari 单击事件有时不打开菜单

    我们的 React PWA 应用程序有问题 我需要群体智能 从 2021 年 10 月开始 我们的部分 iOS 15 用户会出现以下问题 用户单击 触摸
  • MPMediaItemPropertyPercientID 的 NSNumber 到 NSString 并再次返回

    我使用以下代码循环播放 iPhone 音乐库中的所有歌曲 NSArray songs NSArray alloc initWithArray MPMediaQuery songsQuery collections for MPMediaIt
  • UIPageViewController:获取当前页面

    在过去的几天里 我一直在努力解决这个问题 经过所有这些杂耍 我发现我所需要的只是数据源方法中的当前索引 以使用当前可见页码进行更新 我有这个UIPageViewController数据源方法 我需要使用当前索引来获取委托方法的当前可见页面p
  • 如何读取本地 JSON 文件进行测试

    我正在尝试编写用于 json 验证的单元测试 因为该应用程序严重依赖于来自 REST API 的 json 我有一个包含简单 json 的本地文件 goodFeaturedJson txt 内容 test TEST 测试用例 void te
  • 将发布者组合分配给 PassthroughSubject

    我有以下 RxSwift 视图模型代码 private set var num BehaviorRelay
  • BLE (iBeacons) 三边测量

    我是德国富特旺根大学的学生 我已经进入最后一个学期了 现在正在写论文 我对 iBeacons 及其背后的技术非常感兴趣 我当前的项目是将信标技术与 GPS 无线定位 GSM 和 NFC 等其他技术进行比较 对于我的论文 我将创建不同的用例并
  • 我可以/如何确定设备是否有振动?

    我有一些设置可以启用 禁用某些操作的振动 但我发现如果设备没有振动能力 则显示它们毫无意义 有没有办法检查用户是否正在使用 iPod touch 以及它是否有振动 我不确定除了进行模型检查之外还有其他方法可以做到这一点 这可能不是一个很好的
  • iOS 从另一个类更新 ViewController UILabel

    我是开发新手 一直在用头撞墙试图弄清楚这一点 我确信 我错过了一些愚蠢的东西 但在尝试了各种不同的解决方案后 我仍然无法得到结果我在寻找 我希望能够从另一个类更新 ViewController 中的 UILabel 这是一个我无法运行的小演
  • 在 Swift 中,如何检测哪些 UIControl 事件触发了操作?

    我目前有 4 个 UITextField IBOutlet weak var fNameTextField UITextField IBOutlet weak var lNameTextField UITextField IBOutlet
  • reloadData 调用 numberOfSections、numberOfRows,而不是 cellForRowAtIndexPath

    首先 如果格式不正确 我很抱歉 这是第一次这样做 我已经使用 stackoverflow 来寻求帮助很长时间了 它非常有帮助 谢谢大家 但这是我第一次发布自己的问题 这个问题已经被问过很多次了 但是当我调用 myTable reloadTa
  • 如何获取 iTunes connect 团队 ID 和团队名称?

    我正在写下一个Appfile for fastlane 我的问题是我已经有了team name and team id在 Apple 开发中心 但我无法获取iTunes Connect ID itc team id 我正在与不同的团队合作
  • AVAssetExportSession.requestExportSession 回调从未被调用(swift 3,iOS10)

    以下代码从不调用导出回调 导出会话创建得很好 我没有看到任何错误 也没有任何进展 CPU 为 0 我认为没有例外 状态为 1 进行中 进度为 0 错误为零 视频在画廊中播放 我可以成功获取视频的图像 我已将代码提取到单个 UIViewCon
  • 如何检查dispatch_async块是否已完成运行

    所以基本上我需要能够在块完成运行后运行 segue 我有一个块可以执行一些 JSON 操作 我需要知道它何时完成运行 我有一个队列 我称之为 json queue jsonQueue dispatch queue create com ja
  • iOS - 当应用程序被终止时处理静默推送通知

    我目前在 iOS 中遇到推送通知问题 我的应用程序收到包含标识符的静默推送通知 然后 该标识符用于从创建本地通知的远程服务器获取数据 据我所知 如果用户强制退出应用程序 即通过双击主页按钮并滑动关闭应用程序 则静默推送通知不会传递到 App
  • 将 GestureRecogniser 附加到多个图像视图

    今天我在将相同的手势识别器附加到多个图像视图时遇到了一些奇怪的事情 它仅附加到最后一个视图 换句话说 它只能附加到一个视图 我必须创建多个手势识别器才能满足我的要求 以下是我所做的 我做的对吗 这是将识别器附加到多个图像视图的唯一方法吗 请
  • 模拟 Push Segue 的自定义 Segue 将 VC 变成僵尸

    使事情简短明了 我写了一个自定义的segue void perform UIView preV UIViewController self sourceViewController view UIView newV UIViewContro
  • 使用 NSXMLParser 在 Swift 中解析分层 XML

    我确实在以我实际可以使用的形式获取分层 XML 值时遇到问题 因此我们将不胜感激 我对 Swift 和 IOS 开发还很陌生 所以说实话我并不完全理解解析器 但我希望在这之后我能理解 下面是我尝试解析的示例 XML 它来自肥皂网络服务 连接
  • Xcode 8.3 / Xcode 9.0 刷新配置文件设备

    我添加了一些新设备 当 Xcode 8 自动管理签名资产时 如何刷新配置文件 我发现了这个问题 刷新 Xcode 7 管理的团队配置文件中的设备 https stackoverflow com questions 32729193 refr

随机推荐

  • Go 中的通用哈希图

    我正在尝试制作一个包装纸map输入以便我可以添加一些方法 例如contains 这几乎让我怀念Java 但是 我不知道我是否可以在Java中做类似泛型的事情 虽然我读过的几乎所有内容都说 Go 没有泛型类型 但肯定有一种更好的方法 而不是为
  • 如何仅使用私钥文件创建java密钥库?

    我只有一个私钥作为 key 文件 没有其他 crt 或 ca 内容 我需要用它创建一个 java 密钥库 如何转换呢 到目前为止我尝试过的 我将 key 文件重命名为 pem 我使用 openssl 从 pem 中创建了 p12 文件 最后
  • 使用 Gnome-Shell JS 接口获取联系人列表

    我刚刚开始摆弄编写 gnome shell 扩展 并且想知道如何获取用户的联系人列表 我已经找到了一些可能的文件 gnome shell js ui contactDisplay js and gnome shell src shell c
  • 将命令输出解析为变量 LIVE(网络流量监控)

    我正在用 bash 编写一个网络监控脚本 我使用的基本命令是ettercap T M ARP i en1 然后我用管道egrep color Host GET 进去 我得到的示例输出如下所示 GET images srpr logo11w
  • 如何比较sql中的长文本和日期值?

    我以 dd mm yyyy 格式存储日期值作为长文本 我需要将此值与CURDATE 在一个SELECT陈述 请不要问我为什么要以长文本形式保存 有什么办法可以做到吗 这段代码当然不起作用 但它说明了我想要做的事情 WHERE longtex
  • UWP 尝试使用附加的依赖属性对滚动查看器进行动画处理

    我正在尝试在 UWP 中对滚动查看器的水平偏移进行动画处理 但动画目标未识别附加属性
  • 为什么 DateTime.ToString("dd/MM/yyyy") 给我 dd-MM-yyyy ?

    我希望将我的日期时间转换为格式为 dd MM yyyy 的字符串 每当我使用它进行转换时DateTime ToString dd MM yyyy I get dd MM yyyy反而 我必须设置某种文化信息吗 斜杠是日期分隔符 因此将使用当
  • 如何找出 .net 类实现了哪些接口?

    好的 我最近一直在学习 c 和 net c 文档中似乎缺少一件事http msdn microsoft com java 文档中存在 例如数组列表文档 是一个java类的文档会这样说 所有实现的接口 可序列化 可克隆 可迭代 集合 列表 随
  • 如何禁用 grails 中的 log4j 插件?

    看来Grails 2 1 log4j 插件在 grails 应用程序初始化期间重置 log4j 配置 请参阅下面的堆栈跟踪 at org apache log4j LogManager resetConfiguration LogManag
  • 使用 Spark 从 Scala 中的 Dataframe 中的数组列中删除 null (1.6)

    我有一个带有 id 列的数据框和一个具有结构数组的列 架构 root id string nullable true desc array nullable false element struct containsNull true na
  • 提交 HTML 表单后,如何使用 FastAPI 将用户重定向回主页?

    我有一个包含学生表格的页面 我添加了一个按钮 允许您向表中添加新行 为此 我将用户重定向到带有输入表单的页面 问题是 提交完成的表单后 用户会转到一个新的空白页面 如何传输已完成表单中的数据并将用户重定向回表格 我刚刚开始学习Web编程 所
  • Eclipse 插件 - 如何获取编辑器的最后工作

    我正在编写一个 Eclipse 插件 它通过几个按钮向用户公开一个视图 单击任何按钮时 我想将特定注释粘贴到用户当前正在工作的编辑器窗口中以及他指向的光标位置 一旦用户单击该按钮 编辑器窗口就不再具有焦点 并且以下代码不起作用 workbe
  • 来自参数的 Azure 数据工厂源数据集值

    我在 Azure Datafactory 中有一个由 CSV 文件支持的数据集 我在数据集中添加了一个附加列 并希望从数据集参数传递它的值 但值永远不会复制到该列 type AzureBlob structure name MyField
  • 在 where 子句中使用局部变量的替代方法

    我有一个查询 其中有一个使用多个局部变量构建的 where 子句 但这非常慢 以下是一个粗略的示例 因为我当前无权访问该查询 declare a varchar 50 b varchar 50 c varchar 50 set a set
  • 如何配置 ESLint 以允许粗箭头类方法

    ESLint 正在抛出一个Parsing error Unexpected token 当我尝试 lint 我的 Es6 类时出错 我缺少什么配置参数来启用 eslint 中的胖箭头类方法 示例类 class App extends Rea
  • 在 Haskell 中如何轮询文件、套接字或句柄以使其可读/可写?

    我如何从 Haskell 观看多个文件 套接字并等待它们变得可读 可写 Haskell 中有类似 select epoll 的东西吗 或者我被迫为每个文件 套接字生成一个线程 并始终使用该线程内的阻塞资源 这个问题是错误的 你不是force
  • 如何从字符串中去除特定标签和特定属性?

    事情是这样的 我正在做一个项目来帮助人们教授 HTML 我自然是害怕史蒂夫那个渣男 见图1 所以我想阻止ALLHTML 标签 except那些在非常具体的情况下批准的白名单 在那些已批准的 HTML 标签中 我想删除有害的属性以及 例如on
  • 为什么 Spring MVC 报告“找不到类型的返回值的转换器:class org.json.JSONObject”?

    我想返回一个由两个字符串组成的 JSON 但不知道如何实现它 这是我的代码 PostMapping public ResponseEntity lt gt createUser RequestBody User user JSONObjec
  • 避免返回所有实体的学说

    使用Symfony2 doctrine2 当我们使用find 函数根据选择的实体获取特定对象 如果存在关系 时 如OneToMany Doctrine返回所有其他对象 例如 em this gt get doctrine orm entit
  • IOS 自动布局更改旋转位置

    我想将一个容器发送到另一个容器的下方 纵向发送 横向发送并排 仅使用自动布局可以吗 我知道我可以通过编程来做到这一点 只是想知道是否可以从布局中做到这一点 像这样 Well didRotateFromInterfaceOrientation