- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在构建自定义进度条(UIView 的子类)。我将 UIImageView 添加到使用重复图像显示进度的 UIView。 View 被添加到 Storyboard 中,我可以让它显示得很好,但是如果我尝试更改框架,那么它只会显示 Storyboard 文件中显示的内容(即如果 Storyboard View 有黄色背景,但 uiview 子类的代码将其更改为绿色,如果我尝试更改代码中 UIImageView 的框架以反射(reflect)当前进度,则它默认返回黄色背景)
我试过使用这些但没有成功:
[self updateConstraints];
[self layoutSubviews];
更新
我知道我需要设置一个约束以用于自动布局。但是,它需要以编程方式完成,因为我正在以这种方式创建子类 UIView。这是我正在尝试的代码,我知道我很接近但不能让它正常工作:
[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.progressView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationLessThanOrEqual
toItem:nil
attribute:NSLayoutAttributeWidth
multiplier:1
constant:progressWidth]];
[UIView animateWithDuration:3 animations:^{
[self.progressView layoutIfNeeded];
}];
最佳答案
在使用自动布局时,切勿触摸框架。使用像这样的布局系统的全部意义在于,框架是根据附加到它们的可满足约束来推断的。
在不知道更多细节的情况下,解决这个问题的方法是创建从 Storyboard到相关 View 的 NSLayoutConstraint 导出。例如,您可能对进度 View 有宽度限制 - 创建一个 NSLayoutConstraint导出到宽度约束将允许您更新 constant
,这反过来将调整框架。
动画示例:
self.widthConstraint.constant = 300;
[UIView animateWithDuration:0.4 animations:^{
[self.view layoutIfNeeded];
}];
2013 年 5 月 15 日更新
这是一个使用约束的可视化格式以编程方式创建约束的示例(更易于使用)
UIView *w_progressView = self.progressView
NSArray *wc = [NSLayoutConstraint constraintsWithVisualFormat:@"[w_progressView(200)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(w_progressView)];
(抱歉格式化,这是一个很长的方法...)
然后添加NSArray的约束返回给父 View :
[self addConstraints:wc];
符号 progressView(200)
在 View 上放置 200 点宽度progressView
关于iOS - 更改子类 UIView 的 subview 的框架(使用启用自动布局的 Storyboard),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16515616/
我想知道如何首先检测 Javascript 是否启用/禁用。在此站点上禁用 javascript 表明 stackoverflow 使用了称为标签的东西。 这是标准的做法吗?它适用于所有浏览器吗?它不
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How to enable PHP short tags ? Enable short open tags
在 VSTS (Azure DevOps) 上拥有私有(private)存储库我尝试通过将以下内容添加到 .csproj 文件来启用 SourceLink:https://github.com/dot
我创建了一个 wx.Frame(我们称之为 mainFrame)。该框架上包含一个按钮,当单击该按钮时,会创建一个新框架(我们称之为 childFrame)。 我想知道如何在创建 childFrame
当我禁用 WPF 中的控件时,比如说一个菜单项 MenuItem aMenuItem = ... aMenuItem.IsEnabled = false; MenuItem 中的文本仍然处于事件状态,
我想在我的 nginx 服务器上启用 gzip 压缩。 nginx.conf 文件在这里: http { # Enable Gzip server { location ~* \.(?
我正在使用免费的 heroku 附加 PG 备份并遵循这些 instructions .我找到了安装应用程序的命令:heroku addons:add pgbackups:auto-week。但是我想
我想知道脚本是否可以使用某种切换按钮启用/禁用页面上的所有输入元素。 我用谷歌搜索了它,但除了这个之外没有发现任何有用的东西: http://www.codetoad.com/javascript/e
在我的 php 文件中,我想使用 jQuery Datepicker。 当我的文件加载时,我创建了禁用的日期选择器。 然后,当我的 php 文件(它是一个表单)中的一个特殊字段被填充时,我想启用日期选
我有一个按钮,如下所示: RadButton lnkAdd = new RadButton(); lnkAdd.ID = "BtnAdd"; lnkAdd.CommandName = RadGrid.
public static void ToggleTaskManager(string keyValue) { RegistryKey objRegistryK
我正在 Azure 中使用事件网格订阅,该订阅在创建 Blob 时触发。然而,我们有很多文件进入这个 blob,比如说 1000 多个。 如果我发现任何文件有任何错误,我想做的是禁用事件订阅。 最佳答
我的网站上有几个使用 HTML5 contentEditable 属性的 div。目标是让用户能够开始编写日记条目,并将保存按钮从禁用更改为启用。 这是我目前拥有的 HTML: Write
我有一个范围输入,其定义如下: @Html.LabelFor(m => Model.Quality, Resources.CompressionQuality) 和一个下拉菜单: @Html.Lab
我正在尝试创建一个启用/禁用按钮的下拉菜单,并且我正在关注此 example 但它已经有 4 年历史了,而且该功能似乎无法在我的 xhtml 页面上运行。 任何帮助都将被适当 最佳答案 这是一个现场演
我正在 Azure 中使用事件网格订阅,该订阅在创建 Blob 时触发。然而,我们有很多文件进入这个 blob,比如说 1000 多个。 如果我发现任何文件有任何错误,我想做的是禁用事件订阅。 最佳答
我在这里遇到一个非常奇怪的情况:我编写了一个应用程序,除其他外,将连接的代理从打开切换到关闭,反之亦然。通过更改注册表中的值来完成此操作: public void SetUpProxy(string
我需要调整一堆 PVC 的大小。似乎最简单的方法是通过ExpandPersistentVolumes 功能。但是我无法获得配置合作。 ExpandPersistentVolumes feature g
如果我的TextField为空,则应禁用该按钮,并且该按钮的textColor和borderColor应该为灰色。但是,启用按钮后,颜色应为蓝色。 更改textColor很容易: button.Set
您好,我的问题是:我无法从另一个类启用表单的按钮。我的表单类是 public class FileSending { //Function for enabling the button
我是一名优秀的程序员,十分优秀!