Tag: autolayout

UIImageView / UIView的Autolayout宽高比

如何设置UIImageView / UIView的自动布局,使图像视图的宽度和高度增加了一些iphone 6和6 plus。 我已经尝试添加约束长宽比,但增加的高度和宽度是非常大的。 是否有无论如何设置的约束高度和图像视图的宽度可以手动设置iPhone 6和6加。 看看在iphone 6和6加图像视图的截图应该是比现在显示的小一些。

如何设置子视图控制器的topLayoutGuide位置

我正在实现一个自定义的容器,它非常类似于UINavigationController,除了它不包含整个控制器堆栈。 它有一个UINavigationBar,它被限制在容器控制器的topLayoutGuide中,它恰好是顶部20px,这是OK的。 当我添加一个子视图控制器并将其视图放入层次结构中时,我希望在IB中看到它的topLayoutGuide,并用于布置子视图控制器的视图的子视图,使其出现在导航栏的底部。 在相关的文件中有一个要做的事情: 此属性的值特别是查询此属性时返回的对象的length属性的值。 该值受到视图控制器或其封闭容器视图控制器(如导航或选项卡栏控制器)的约束,如下所示: 不在容器视图控制器中的视图控制器约束此属性以指示状态栏的底部(如果可见) 否则指示视图控制器视图的上边缘。 容器视图控制器中的视图控制器不会设置此属性的值。 相反,容器视图控制器限制值以指示: 导航栏的底部,如果导航栏是可见的 状态栏的底部,如果只有一个状态栏是可见的 视图控制器视图的顶部边缘,如果状态栏和导航栏都不可见的话 但是我不太了解如何“限制它的价值”,因为topLayoutGuide和它的长度属性都是只读的。 我已经试过这个代码来添加一个子视图控制器: [self addChildViewController:gamePhaseController]; UIView *gamePhaseControllerView = gamePhaseController.view; gamePhaseControllerView.translatesAutoresizingMaskIntoConstraints = NO; [self.contentContainer addSubview:gamePhaseControllerView]; NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[gamePhaseControllerView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(gamePhaseControllerView)]; NSLayoutConstraint *topLayoutGuideConstraint = [NSLayoutConstraint constraintWithItem:gamePhaseController.topLayoutGuide attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.navigationBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0]; NSLayoutConstraint *bottomLayoutGuideConstraint = [NSLayoutConstraint constraintWithItem:gamePhaseController.bottomLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1 […]

UIScrollView的高度和contentOffsetanimation从底部“跳”内容

试图做一些类似于Messages.app的行为,我有一个UIScrollView并在它下面的文本字段,并尝试进行animation处理,以便当键盘出现时,所有东西都移动到键盘上方使用一个约束,而且由于自动布局, UIScrollView的高度也会改变),同时设置contentOffset滚动到底部。 代码完成想要的最终结果,但是在animation的右侧,当键盘animation开始时,滚动视图变为空白,然后内容从底部向上滚动,而不是从animation开始时的位置滚动。 animation是这样的: – (void)updateKeyboardConstraint:(CGFloat)height animationDuration:(NSTimeInterval)duration { self.keyboardHeight.constant = -height; [self.view setNeedsUpdateConstraints]; [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ [self.view layoutIfNeeded]; self.collectionView.contentOffset = CGPointMake(0, self.collectionView.contentSize.height – self.collectionView.bounds.size.height); } completion:nil]; } 这个问题的video可以在这里find 。 谢谢!

使用自动布局,如何使UIImageView的大小dynamic取决于图像?

我想我的UIImageView增长或缩小取决于它显示的实际图像的大小。 但是我希望它能够保持垂直居中,距离超级观点的前沿10点。 但是,如果我设置这两个约束,它抱怨我没有设置足够的约束来满足自动布局。 对我来说,它似乎完美地描述了我想要的。 我错过了什么?

UIStackView“无法同时满足约束”对“压缩”的隐藏视图

当我的UIStackView“行”被挤压,他们抛出AutoLayout警告。 但是,它们显示正常,除了这些logging之外没有别的错误: 无法同时满足约束。 下面列表中的至less一个约束可能是你不想要的。 试试这个:(1)看看每一个约束,并试图找出你不期望的; (2)find添加不需要的约束或约束的代码并修复它。 (注意:如果你看到你不明白的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性的文档translatesAutoresizingMaskIntoConstraints)( 所以,我不知道如何解决这个问题,但除了只是烦人之外,似乎没有什么可以打破的。 有谁知道如何解决它? 有趣的是,布局约束常常被标记为“UISV-hiding” ,表明可能应该忽略子视图的高度最小值或在这种情况下的某些东西?

每当我的应用程序启动时,为什么我会在执行“-layoutSubviews”后仍然需要“自动布局”?

由于我添加了下面的代码,每当我的应用程序打开这个UITableViewController它崩溃: self.noArticlesView = [[UIView alloc] init]; self.noArticlesView.translatesAutoresizingMaskIntoConstraints = NO; self.noArticlesView.backgroundColor = [UIColor colorWithRed:0.961 green:0.961 blue:0.961 alpha:1]; [self.view addSubview:self.noArticlesView]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]]; 它给了我这个错误: […]

无法同时满足约束embedded在故事板中的AVPlayerViewController的警告

我试图通过embedded一个单独的视图控制器完全通过故事板设置一个AVPlayerViewController。 脚步: 在Xcode中创build单一视图应用程序。 将VCembedded到导航控制器中。 在底部添加工具栏(固定到超级视图(前导,尾随,底部布局指南,高度(44))。 在父视图控制器中添加容器视图(固定到超视图(前导,尾随),顶部布局指南,工具栏顶部)。 删除容器视图附带的默认视图控制器。 从对象库拖动AV Player视图控制器对象。 将容器视图中的embedded式Segue连接到AV播放器视图控制器。 没有添加代码。 这是我的故事板的样子: 查看层次: 一切运行良好: 但问题是:只要我运行它,我得到这些警告在debugging器中: 2015-09-30 12:58:35.904 AVPlayerTest[9352:446772] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; […]

iOS 11关于iPhone x安全区域的布局指南

我的应用程序已经在应用程序商店,昨天我已经更新了我的Xcode版本为9,并且工作正常,除了iPhone X。 用户界面崩溃了。 1.我有创build两个UIView (都是固定的高度)命名为标题和选项卡栏,我已经隐藏了我的NavigationBar整个应用程序。 2.添加扩展到UIViewController的标题和标签栏 func addHeaderTab(currentViewController:UIViewController,content:String, isMenu:Bool){ let noView = TopHeaderView() noView.tag = 12345 noView.isMenu = isMenu noView.translatesAutoresizingMaskIntoConstraints = false currentViewController.view .addSubview(noView) if isMenu{ noView.menuBtn .setImage(UIImage(named: "Small"), for: .normal) noView.logoImg.isHidden = false }else{ noView.menuBtn .setImage(UIImage(named: "arrow_small"), for: .normal) noView.logoImg.isHidden = true } noView.titleLbl.text = content noView.delegate = (currentViewController as! menuOpen) NSLayoutConstraint(item: noView, attribute: […]

如何使用自动布局animationUITableViewCell高度?

有关堆栈溢出关于UITableViewCell高度animation很多类似的问题,但没有什么适用于新的iOS8自动布局驱动的表视图。 我的问题: 定制单元格: @property (weak, nonatomic) IBOutlet iCarousel *carouselView; @property (weak, nonatomic) IBOutlet UIPageControl *pageControl; @property (weak, nonatomic) IBOutlet UIButton *seeAllButton; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *carouselHeightConstraint; 注意carouselHeightConstraint 。 这是内容视图的子视图(唯一的子视图)的高度限制。 例如,高度设置为230.0f 。 在第一次加载它看起来像: 然后,在查看所有操作我想展开单元格,我的代码: – (IBAction)seeAllButtonAction:(id)sender { BOOL vertical = !self.carouselCell.carouselView.vertical; self.carouselCell.carouselView.type = vertical ? iCarouselTypeCylinder : iCarouselTypeLinear; self.carouselCell.carouselView.vertical = vertical; [UIView transitionWithView:self.carouselCell.carouselView duration:0.2 options:0 […]

iOS 7.1 UitableviewCell内容与下面的内容重叠

所以我有代码,这是成功的iOS 7.0,但不是在7.1。 我有一个简单的tableview,用代码: – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70.0; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; for (UIView *view in cell.contentView.subviews) { [view removeFromSuperview]; } UILabel *label = [[UILabel alloc] init]; label.text […]