小编Pad*_*215的帖子

UIView和intrinsicContentSize

UIView是否创造了intrinsicContentSize

我创建了一个UIView contentView.我不给它约束大小:

UIView *contentView = [UIView new];
[contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
contentView.backgroundColor = [UIColor orangeColor];
Run Code Online (Sandbox Code Playgroud)

我创建了另一个UIView subview01.我给它约束大小并将其添加到我的contentView:

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
imageView.userInteractionEnabled = TRUE;
imageView.backgroundColor = [UIColor clearColor];

[imageView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView(WIDTH)]"
                                                                  options:0
                                                                  metrics:@{@"WIDTH" : [NSNumber numberWithFloat:imageSize.width]}
                                                                    views:NSDictionaryOfVariableBindings(imageView)]];

[imageView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageView(HEIGHT)]"
                                                                  options:0
                                                                  metrics:@{@"HEIGHT" : [NSNumber numberWithFloat:imageSize.height]}
                                                                    views:NSDictionaryOfVariableBindings(imageView)]];


[contentView addSubview:imageView];
Run Code Online (Sandbox Code Playgroud)

contentView确实没有任何大小.我想intrinsicContentSize是假设要计算显示所有子视图所需的大小并自行调整大小?就像UILabel如何调整大小以显示其所有文本一样?

objective-c ios autolayout nslayoutconstraint

5
推荐指数
1
解决办法
5530
查看次数

应用程序验证失败:无法创建配置目录:/user/username/.itmstransporter

我最近切换到另一台计算机进行编程.这是另一个同事的电脑,没有重新格式化.我在上面安装了xCode.这是我第一次尝试在这台机器上更新我们的应用程序.我存档了w/out错误,我验证了w/out错误.当我去提交时,我得到这两个错误:


*无法创建配置目录:/Users/username/.itmstransporter

*您的主文件夹必须是可写的,以便保存运行时配置数据.请确保您的主文件夹存在且可写.


我不是一个Mac OS的人,几乎无法绕过mac.检查了同事,我确实有/ Users目录的读/写权限.

我可以解决这个问题,还是需要重新安装xCode或操作系统?

xcode objective-c ios

4
推荐指数
1
解决办法
1812
查看次数

NSLayoutConstraint并相互"附加"两个标签

我有两个标签.如果移动一个,我希望能够移动它们.如何将它们与NSLayoutConstraints"连接"在一起?我可以在IB中执行此操作,但需要在代码中执行此操作.

另外,什么是NSLayoutAttributeBaseline,NSLayoutAttributeLeading和NSLayoutAttributeTrailing?

编辑:

中心poweredByLabel(又名label02):

[constraints addObject:[NSLayoutConstraint constraintWithItem:poweredByLabel
                                                    attribute:NSLayoutAttributeCenterX
                                                    relatedBy:NSLayoutRelationEqual
                                                       toItem:myImage
                                                    attribute:NSLayoutAttributeCenterX
                                                   multiplier:1.0
                                                     constant:0]];
Run Code Online (Sandbox Code Playgroud)

堆叠标签并垂直切换:

[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[rememberPasswordSwitch]-10-[rememberPasswordLabel]-10-[versionLabel]-[poweredByLabel]-|"
                                                                         options:NSLayoutFormatAlignAllBaseline
                                                                         metrics:nil
                                                                           views:viewsDictionary]];
Run Code Online (Sandbox Code Playgroud)

产生错误:

*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'无法解析约束格式:选项掩码要在垂直边缘上对齐的视图,这对于也是垂直的布局是不允许的.五:[rememberPasswordSwitch] -10- [rememberPasswordLabel] -10- [versionLabel] - [poweredByLabel] - | ........................... .................................................. .............................. ^"

w/out NSLayoutFormatAlignAllBaseline选项,它运行正常(它们堆栈但不是全部水平居中).

objective-c ios nslayoutconstraint

4
推荐指数
1
解决办法
6854
查看次数

NSLayoutConstraint和MKMapView

在我的viewDidLoad方法中,我有代码来创建MKMapView,一些约束和一个UIToolbar:

我有一个MKMapView:

MKMapView *mapView = [[MKMapView alloc] init];
[mapView setTranslatesAutoresizingMaskIntoConstraints:NO];
mapView.userInteractionEnabled = TRUE;
mapView.showsUserLocation = TRUE;
mapView.mapType = MKMapTypeHybrid;
mapView.delegate = self;

[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];

[self.view addSubview:mapView];
Run Code Online (Sandbox Code Playgroud)

我创建了2个约束来使其全屏显示:

NSMutableArray *constraints = [NSMutableArray array];

[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[mapView]|"
                                                                         options:0
                                                                         metrics:nil
                                                                           views:NSDictionaryOfVariableBindings(mapView)]];

[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|[mapView]|"
                                                                         options:0
                                                                         metrics:nil
                                                                           views:NSDictionaryOfVariableBindings(mapView)]];

[self.view addConstraints:constraints];
Run Code Online (Sandbox Code Playgroud)

效果很好.但是当我尝试向地图视图添加任何内容时:

 UIToolbar *topBar = [[UIToolbar alloc ]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
[topBar setTranslatesAutoresizingMaskIntoConstraints:NO];
topBar.barStyle = UIBarStyleBlackTranslucent;

[mapView addSubview:topBar];
Run Code Online (Sandbox Code Playgroud)

它会抛出一个错误:

*** Assertion failure in -[MKMapView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776
2013-01-10 10:24:17.503 Landscout 2[2001:14003] *** Terminating app due …
Run Code Online (Sandbox Code Playgroud)

objective-c ios nslayoutconstraint

4
推荐指数
1
解决办法
2496
查看次数

如何使用渐变和突出显示创建UIButton?

我正在尝试创建一个渐变背景的UIButton.我选择时工作正常,但按钮不突出显示(默认行为是按钮变暗).

这是我的按钮:

-(UIButton *)createLoginButtonForSize:(CGSize)size {
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    loginButton.translatesAutoresizingMaskIntoConstraints = FALSE;
    loginButton.layer.cornerRadius = 8;
    loginButton.titleLabel.text = @"Login";

    [loginButton addTarget:self action:@selector(loginCheck:) forControlEvents:UIControlEventTouchUpInside];


    [loginButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[loginButton(WIDTH)]"
                                                                        options:0
                                                                        metrics:@{@"WIDTH": [NSNumber numberWithFloat:size.width]}
                                                                          views:NSDictionaryOfVariableBindings(loginButton)]];

    [loginButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[loginButton(HEIGHT)]"
                                                                        options:0
                                                                        metrics:@{@"HEIGHT": [NSNumber numberWithFloat:size.height]}
                                                                          views:NSDictionaryOfVariableBindings(loginButton)]];

    CAGradientLayer *layer = [UIColor greenGradient];
    layer.frame = CGRectMake(0, 0, size.width, size.height);
    layer.cornerRadius = 8;

    [loginButton.layer insertSublayer:layer atIndex:0];

    return loginButton;
}
Run Code Online (Sandbox Code Playgroud)

我需要自己处理突出显示吗?

objective-c uibutton ios cagradientlayer

4
推荐指数
1
解决办法
4034
查看次数

NSManagedObject; 保持或加载到自定义NSObject?

我正在使用Core Data来存储对象.我有一个NSManagedObject人和一个NSObject人.它们都具有相同的属性.在NSObject有一些方法.

现在,我为Bob搜索Core Data.然后我拿起NSManagedObjectBob并将所有属性复制到NSObjectBob并用它做我需要的.

这是否有意义或者我应该创建所需的方法NSManagedObject?可以NSManagedObject像对待一样对待NSObject吗?

core-data objective-c nsmanagedobject ios

4
推荐指数
1
解决办法
1539
查看次数

Apple Map (MKMapView) Mercator Projection 的 EPSG

我似乎无法找到 Apple Map 的墨卡托投影使用的投影。他们的指南上没有说:

位置意识指南

有人知道吗?

objective-c mkmapview ios

4
推荐指数
1
解决办法
2187
查看次数

Xcode 5 Autolayout并使UIView的宽度等于高度

我正在使用autolayout.我在IB中有一个UIImageView.我想让它的宽度等于它的高度.

我学会了如何在Xcode 4中完成大部分这些工作.我知道如何以编程方式完成它,但这产生了错误并且还没有修复Apple:

'Auto Layout still required after executing -layoutSubviews. UITableViewCell's implementation of -layoutSubviews needs to call super.'
Run Code Online (Sandbox Code Playgroud)

那么如何在Xcode 5 Interface Builder中设置这个约束呢?

ios autolayout xcode5

4
推荐指数
1
解决办法
5207
查看次数

Autolayout和UIPopoverController

我在其中创建了一个包含一些子视图的面板,并使用NSLayoutConstraints来实现定位.

我会把它显示在一个UIPopoverController.在设置它之前,我会调用[UIView layoutIfNeeded]命令强制它自己调整大小(整体大小基于其中可能是不同大小的图像的大小).

PhotoDisplayPanel *panel = [[PhotoDisplayPanel alloc] initWithPhoto:cell.photo isAddPhoto:cell.isAddPhoto];

DLog(@"BEFORE | panel.frame: %@", panel);

[self.view addSubview:panel];

DLog(@"MIDDLE | panel.frame: %@", panel);

[panel layoutIfNeeded];

DLog(@"AFTER | panel.frame: %@", panel);
Run Code Online (Sandbox Code Playgroud)

日志:

DEBUG | -[LoginViewController viewDidLoad] | BEFORE | panel.frame: <PhotoDisplayPanel: 0x7878a3f0; frame = (0 0; 0 0); layer = <CALayer: 0x7878a7e0>>
DEBUG | -[LoginViewController viewDidLoad] | MIDDLE | panel.frame: <PhotoDisplayPanel: 0x7878a3f0; frame = (0 0; 0 0); layer = <CALayer: 0x7878a7e0>>
DEBUG | -[LoginViewController viewDidLoad] …
Run Code Online (Sandbox Code Playgroud)

objective-c uipopovercontroller ios nslayoutconstraint

4
推荐指数
1
解决办法
1424
查看次数

UIScrollView在iOS11中不滚动

我已经创建了一个UIScrollView代码,它可以在iOS10中运行.我今天更新了我的Xcode并且它不再在iOS11中滚动(模拟器是iOS11并且不起作用;物理iPad仍然是iOS10并且可以工作).

用户可以在需要时添加子视图.当它是第一个子视图时,我将它锚定到滚动视图的左侧,顶部和底部.然后我将子视图的右侧锚定到滚动视图的右侧,它给出了contentSize它的大小,因此它知道它需要启用滚动

UIScrollView *scrollViewMain = [UIScrollView new];
scrollViewMain.delegate = self;
scrollViewMain.backgroundColor = [UIColor greenColor];
scrollViewMain.translatesAutoresizingMaskIntoConstraints = NO;
scrollViewMain.directionalLockEnabled = YES;
self.scrollViewMain = scrollViewMain;

... // other code

if (self.countPlayers == 1) {
    [self.scrollViewMain addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[playerCardView(400)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(playerCardView)]];
    [self.scrollViewMain addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[playerCardView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(playerCardView)]];

    NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.scrollViewMain attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:playerCardView attribute:NSLayoutAttributeRight multiplier:1 constant:10];

    self.constraintScrollViewRight = constraint;

    [self.scrollViewMain addConstraint:constraint];
}
else {
    [self.scrollViewMain addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[previousPlayerCardView]-[playerCardView(==previousPlayerCardView)]" options:0 metrics:nil views:@{@"previousPlayerCardView": player.previousPlayer.playerViewCard, @"playerCardView": player.playerViewCard}]];

    [self.scrollViewMain addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[playerCardView]|" options:0 …
Run Code Online (Sandbox Code Playgroud)

objective-c uiscrollview nslayoutconstraint ios11

4
推荐指数
2
解决办法
1316
查看次数