小编Wer*_*nzy的帖子

自动布局iOS 7 - 无法将子视图右侧与UIScrollView右侧对齐

我以编程方式构建视图并使用autolayout,根本没有界面构建器.在自定义ScrollView控制器中,我添加了UILabel和UIButton作为子视图.我想将标签对齐到屏幕左侧,按钮位于屏幕右侧.出于某种原因,我的按钮仅对齐我的滚动视图的左侧.我已经减少了我的代码,所以它只是这两个标签,我无法理解为什么它不会正确对齐.

HWScrollViewController.m(我如何初始化主滚动视图)

- (void)loadView
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

    self.scrollView.delegate = self;

    self.view = self.scrollView;
}
Run Code Online (Sandbox Code Playgroud)

HWListingDetailViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];

UILabel *priceLabel = [[UILabel alloc] init];
UIButton *favouriteButton = [UIButton buttonWithType:UIButtonTypeContactAdd];

[priceLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[favouriteButton setTranslatesAutoresizingMaskIntoConstraints:NO];

[priceLabel setText:@"$125.00"];
[favouriteButton setTitle:@"Add to Favourites" forState:UIControlStateNormal];

[self.view addSubview:priceLabel];
[self.view addSubview:favouriteButton];

[self.view addConstraints:@[
    [NSLayoutConstraint constraintWithItem:priceLabel 
                                 attribute:NSLayoutAttributeCenterY
                                 relatedBy:NSLayoutRelationEqual 
                                    toItem:self.view 
                                 attribute:NSLayoutAttributeCenterY 
                                multiplier:1 
                                  constant:0],

    [NSLayoutConstraint constraintWithItem:priceLabel 
                                 attribute:NSLayoutAttributeLeft 
                                 relatedBy:NSLayoutRelationEqual 
                                    toItem:self.view 
                                 attribute:NSLayoutAttributeLeft 
                                multiplier:1 
                                 constant:5],

    [NSLayoutConstraint constraintWithItem:favouriteButton 
                                 attribute:NSLayoutAttributeCenterY 
                                 relatedBy:NSLayoutRelationEqual 
                                    toItem:self.view 
                                 attribute:NSLayoutAttributeCenterY 
                                multiplier:1 
                                  constant:0],

    [NSLayoutConstraint constraintWithItem:favouriteButton 
                                 attribute:NSLayoutAttributeRight …
Run Code Online (Sandbox Code Playgroud)

uiscrollview ios autolayout nslayoutconstraint ios7

10
推荐指数
1
解决办法
8125
查看次数

邀请朋友通过Facebook使用我的ios应用程序

我刚刚开始研究现有的项目,我应该添加一些功能来邀请你的Facebook好友使用该应用程序.它正在使用Parse的PFFacebookUtils进行连接,我正在尝试使用Facebook API来获取您的整个朋友列表,以便您可以选择它们并邀请他们下载和使用该应用程序.

既然V2 API是可能的呢?据我所知,你只能得到一个已经使用过应用程序的朋友列表(没用),或者你可以获得一个"邀请朋友"列表,但前提是它只是一个Facebook Canvas游戏,这个应用程序不是.我认为邀请人们通过Facebook使用你的应用程序是一个非常常见的功能,但Facebook已经弃用了这种能力?我希望有人知道我不知道的事情,并且有办法实现这一目标.

提前致谢!

facebook facebook-graph-api ios

8
推荐指数
1
解决办法
3612
查看次数

UIScrollView 内的 UIStackView,增长到最大高度然后滚动

我正在寻找构建一个视图,该视图将随着子视图的添加而增长。起初高度将为零,然后应该随着我添加子视图而增长,直到达到最大尺寸,然后我希望它变得可滚动。

如果我使用 UIScrollView 中的 UIView 构建它并手动设置从上到下的约束,它会按预期工作。但是,我觉得使用 UIStackView 应该可以做到这一点,但是当我尝试滚动视图不增长,或者 scrollView 的 contentSize 卡在最大高度时,不会滚动。我已经玩了一段时间,并认为它实际上可能是 UIStackView 和 Autolayout 的一个错误,但希望我只是错过了一些东西。将 UIStackView 包装在容器 UIView 中没有帮助。

这是一个完整的视图控制器,它显示了问题(点击任何地方都会向滚动视图添加标签)

import UIKit

class DumbScrollStack: UIViewController {

    let stack = UIStackView()
    let scrollView = UIScrollView()

    override func viewDidLoad() {
        super.viewDidLoad()

        //Setup
        view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(addLabel)))
        stack.axis = .vertical
        view.backgroundColor = .blue
        scrollView.backgroundColor = .red

        //Add scroll view and setup position
        view.addSubview(scrollView)
        scrollView.translatesAutoresizingMaskIntoConstraints = false
        scrollView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        scrollView.topAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        scrollView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true

        //Set maximum height
        scrollView.heightAnchor.constraint(lessThanOrEqualToConstant: …
Run Code Online (Sandbox Code Playgroud)

uiscrollview ios autolayout swift uistackview

7
推荐指数
1
解决办法
881
查看次数

可以在 iOS 14 上使用键盘类型 emailAddress 隐藏 UITextField 上的预测文本栏吗?

我有一个 UITextField 供用户输入他们的电子邮件地址。我想将 KeyboardType 设置为 UIKeyboardTypeEmailAddress,以便它们具有 @ 和 . 键很快可用,但我不希望键盘在其上方显示带有电子邮件地址建议的自动完成栏。在过去和其他 SO 帖子中,我看到将 auto CorrectionType 设置为 UITextAuto CorrectionTypeNo 应该会删除该栏,但在 iOS 14 上它仍然存在。iOS 14 有什么办法可以去掉这个栏吗?

提前致谢!

uitextfield ios ios14

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

存储在Objective-C中的Keychain的值无法在Swift中检索?

我遇到了钥匙扣最棘手的问题.我有一个现有的应用程序,它是使用加密的境界数据库,加密密钥被保存到钥匙扣,按Realm公司的代码示例在这里.

- (NSData *)getKey {
    // Identifier for our keychain entry - should be unique for your application
    static const uint8_t kKeychainIdentifier[] = "io.Realm.EncryptionExampleKey";
    NSData *tag = [[NSData alloc] initWithBytesNoCopy:(void *)kKeychainIdentifier
                                               length:sizeof(kKeychainIdentifier)
                                         freeWhenDone:NO];

    // First check in the keychain for an existing key
    NSDictionary *query = @{(__bridge id)kSecClass: (__bridge id)kSecClassKey,
                            (__bridge id)kSecAttrApplicationTag: tag,
                            (__bridge id)kSecAttrKeySizeInBits: @512,
                            (__bridge id)kSecReturnData: @YES};

    CFTypeRef dataRef = NULL;
    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &dataRef);
    if (status == errSecSuccess) {
        return (__bridge NSData *)dataRef; …
Run Code Online (Sandbox Code Playgroud)

objective-c keychain ios swift

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

Xcode 11 Beta 7命令PhaseScriptExecution失败,退出代码为非零([CP] Copy Pods Resources)

最近下载了Xcode 11 Beta,以在iOS 13中测试我的应用程序,但遇到了一个似乎无法解决的问题。每次在[CP] Copy Pods Resources步骤上构建都会失败,并说“命令PhaseScriptExecution失败,退出代码非零”。现在我知道这是任何运行脚本阶段失败时的错误,但是通常会伴随此错误提供一些有用的信息。

错误输出:

ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target 11.0 --output-format human-readable-text --compile /Users/chris/Library/Developer/Xcode/DerivedData/SmartPager-dcfjsnhrgkjfeabbvafghvwsrsxr/Build/Products/Debug-iphoneos/SmartPager Sandbox.app/JSQMessagesViewController.nib 
/Users/chris/Work/projectname/Pods/JSQMessagesViewController/JSQMessagesViewController/Controllers/JSQMessagesViewController.xib --sdk /Users/chris/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk --target-device ipad --target-device iphone
2019-09-06 13:26:17.003 IBAgent-iOS[39395:514843] Incorrect screen size for <UIScreen: 0x7fb0e05245a0; bounds = {{0, 0}, {0, 0}}> in UICollectionViewData
ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target 11.0 --output-format human-readable-text --compile /Users/chris/Library/Developer/Xcode/DerivedData/SmartPager-dcfjsnhrgkjfeabbvafghvwsrsxr/Build/Products/Debug-iphoneos/SmartPager Sandbox.app/JSQMessagesCollectionViewCellIncoming.nib /Users/chris/Work/projectname/Pods/JSQMessagesViewController/JSQMessagesViewController/Views/JSQMessagesCollectionViewCellIncoming.xib --sdk /Users/chris/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk --target-device ipad --target-device iphone
Command PhaseScriptExecution failed with a nonzero exit code
Run Code Online (Sandbox Code Playgroud)

相关信息:据我所知,这可能与我们使用的已弃用的cocoapod有关,特别是JSQMessagesViewController(7.3.5)。显然,使用不赞成使用的库并不是很好,但是它可以在Xcode 10中构建并正常运行,因此我不知道问题可能出在哪里。在一个单独的项目中,我尝试仅添加此pod,它会引发相同的错误。关于“屏幕大小不正确...”的行似乎只是警告而不是错误,因为在Xcode 10中,它使用同一行正确编译。

我尝试过重新启动计算机,清理,删除派生数据以及所有常见的东西。我只是不知道现在还能去哪里。任何建议将不胜感激。谢谢!

xcode ios ios13 xcode11

3
推荐指数
2
解决办法
710
查看次数