小编Wil*_*ich的帖子

iOS 11 UISearchBar背景色

据我所知,这个问题已经被问过很多,很多倍左右.然而,随着Apple的发布最好,随着iOS 11的发布,它们似乎已经对它进行了一个看似不必要的改变UISearchBar,特别是它的视图层次结构.

此外,搜索栏的子视图中不再可访问搜索栏的"文本字段",导致所有先前的解决方案"访问"并更改文本字段的背景颜色或文本字段的任何属性那件事.

  • 有谁知道如何在iOS 11中实际调整搜索栏的背景颜色?

仅供参考: 我特别谈到文本背后的颜色......除非您将搜索栏样式指定为最小,否则现在从11开始默认为白色.

更新1:

因为我这个问题的帖子,我还没有找到一个有效的还是真的任何 真正解决这个问题.我似乎最接近的是深入了解外观,例如属性

[[UISearchBar class] appearanceWhenContainedInInstancesOfClasses:(nonnull NSArray<Class<UIAppearanceContainer>> *)]
Run Code Online (Sandbox Code Playgroud)

UISearchBar.使用以下找到的UITextFieldvia方法:

if ([view isKindOfClass:[UITextField class]]) {
    return (UITextField*)view;
}
UITextField *searchTextField;
for (UIView *subview in view.subviews) {
    searchTextField = [self searchViewForTextFieldBg:subview];
    if (searchTextField) {
        break;
    }
}
return searchTextField;
Run Code Online (Sandbox Code Playgroud)

您可以开始绘制要放置在视图后面的背景视图.然而,我发现过于繁琐而无法继续追求的问题是用正确的框架/边界绘制一个视图来模仿原始背景.

希望有人能找到这个问题的实际解决方案.好想念苹果......

objective-c uisearchbar ios swift ios11

10
推荐指数
3
解决办法
8205
查看次数

iOS 11设备方向自动旋转

对于iOS 10及更低版本,以下代码控制任何相应的方向UIViewController.我选择了Portrait,Landscape LeftLandscape Right我的部署信息,并在我下面的Info.plist:

在此输入图像描述

对于那些根本应该旋转的VC,我有以下代码,我说过,它在iOS 11之前工作

- (BOOL)shouldAutorotate {
    [super shouldAutorotate];
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    [super supportedInterfaceOrientations];
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

我已经在实际设备上测试了这个,而且从iOS 11开始它不起作用.

更奇怪的是,从iOS 11开始记录已注册的设备方向告诉我设备纵向...当控制器以横向模式加载时......

码:

// In viewDidLoad 
NSLog(@"orientation: %lu", [[UIDevice currentDevice] orientation]);
Run Code Online (Sandbox Code Playgroud)

控制台输出:

2017-09-22 15:20:26.225196-0400 <APP_NAME>[2669:1628408] orientation: 1
Run Code Online (Sandbox Code Playgroud)

这可能是在构建和运行应用程序之前向左或向右旋转设备.


  • 这个错误的原因是什么?如果有人知道请帮助..

仅供参考:不,我的设备上没有旋转锁定..

objective-c orientation ios swift ios11

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

键盘扩展内存泄漏?

我正在构建一个自定义键盘扩展(iOS 9+),并发现了一个令人烦恼的内存泄漏.

当离开应用程序(在此测试用例中为Messages应用程序)然后返回时,会发生此泄漏.通常(见下面Xcode的Instruments7的照片)

我确实没有对模板做任何事情,但收到了这个漏洞.有没有人对如何解决这个问题有任何建议?...

UPDATE

为了好玩,这里的辉煌泄露的屏幕截图... 第一我复杂的VC的片段....

这是在点击文本字段,关闭控制器,然后再次点击该字段之后

(显示 - >隐藏 - >显示)

#import "KeyboardViewController.h"

@implementation KeyboardViewController 

- (void)viewDidLoad {

    [super viewDidLoad];

}

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

}

@end
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

keyboard xcode memory-leaks ios

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

GKGoal 避免边界障碍

我似乎很难将我的精灵节点保持在我通过以下方式设置的地图边界内:

我有一个SKNode *enemy是围绕移动SKScene通过的目标和行为礼貌GameplayKit从iOS版9.目前的节点飘荡,避免障碍物被定义GKPolygonObstacle对象。我设置了我的位掩码,以便任何障碍物都被认为是类别wall,节点被告知要与之碰撞(AKA 不允许通过)。

在我中,didBeginContact:(SKPhysicsContact *)contact我正在处理这些碰撞。一切都按计划进行,手动移动这个敌人时没有问题。

然而,当我让敌人通过一个SKGoal *wanderGoal设置在场景中四处游荡时,问题就开始了。

    // Low --> 0.5     Lowest --> 0.25
    enemy.wanderGoal = [GKGoal goalToWander:low];
    [enemy.agent.behavior setWeight:lowest forGoal:enemy.wanderGoal];

    // Add obstacles to avoid for each of the inner map nodes
    // that act as impassible areas for the enemy to pass through.
    NSArray *obstacles = [SKNode obstaclesFromNodePhysicsBodies:innerMapArray];

    /** This goal does not change --> enemies will ALWAYS
     avoid the obstacles in …
Run Code Online (Sandbox Code Playgroud)

objective-c game-physics ios sprite-kit gameplay-kit

7
推荐指数
0
解决办法
300
查看次数

SpriteKit SKPhysicsBody with Inner Edges

我创建了一个SKSpriteNode名为let的说Map,它具有我定义的边缘路径(一些简单的多边形形状).

我想弄清楚的是如何添加几个其他边缘路径作为Map的内部边缘.好像整个"地图"确实有漏洞.某种内部边界形状可以与Map作为一个整体起作用:一条边缘路径(如下所示)

在此输入图像描述 ©

我知道有一种方法可以创建一个SKPhysicsBodywith body(一些NSArray),就像这样

Map.physicsBody = [SKPhysicsBody bodyWithBodies:bodiesArray];
Run Code Online (Sandbox Code Playgroud)

这种方法实际上是否产生了我在图像中显示的内容?假设bodiesArray包含3 SKSpriteNode的每个都有一个使用这种方法的定义路径:

+ (SKPhysicsBody *)bodyWithEdgeChainFromPath:(CGPathRef)path
Run Code Online (Sandbox Code Playgroud)

,创造这样的道路

        SKSpriteNode *innerNode1 = [SKSpriteNode spriteNodeWithImageNamed:@"map"];

        CGMutablePathRef innerNode1Path = CGPathCreateMutable();

        CGPathMoveToPoint(mapPath, NULL, 1110, 1110);
        CGPathAddLineToPoint(mapPath, NULL, <some x1>, <some y1>);
        CGPathAddLineToPoint(mapPath, NULL, <some x2>, <some y2>);
        CGPathAddLineToPoint(mapPath, NULL, <some x3>, <some y3>);
        . 
        .
        .
        CGPathCloseSubpath(mapPath);

        innerNode1.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:innerNode1Path];
        [bodiesArray addObject:innerNode1];

        // Repeat for other 2 nodes
Run Code Online (Sandbox Code Playgroud)

我知道另一种方法是创建3个单独的节点,其中包含预期"洞"的位置和形状,但我想要避免创建比我需要的节点更多的节点.如果有人能够确认我想要做的是正确的,或者可能提出一个我不知道的替代方案. …

game-physics ios sprite-kit skphysicsbody skspritenode

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

设备与模拟器语言方案

有谁知道为什么会这样?

在任何模拟器上都可以找到所有方案,代码如下:

NSArray<NSLinguisticTagScheme> *availSchemes = [NSLinguisticTagger availableTagSchemesForLanguage:@"en"];
for (NSLinguisticTagScheme scheme in availSchemes) {
    NSLog(@"Tag scheme %@", scheme);
}
Run Code Online (Sandbox Code Playgroud)

得出以下结论:

2018-02-13 09:12:54.066970-0500 MY_APP[79671:5737063] Tag scheme Language
2018-02-13 09:12:54.067160-0500 MY_APP[79671:5737063] Tag scheme Script
2018-02-13 09:12:54.067300-0500 MY_APP[79671:5737063] Tag scheme TokenType
2018-02-13 09:12:54.067425-0500 MY_APP[79671:5737063] Tag scheme LexicalClass
2018-02-13 09:12:54.067541-0500 MY_APP[79671:5737063] Tag scheme NameType
2018-02-13 09:12:54.067655-0500 MY_APP[79671:5737063] Tag scheme NameTypeOrLexicalClass
2018-02-13 09:12:54.067768-0500 MY_APP[79671:5737063] Tag scheme Lemma
Run Code Online (Sandbox Code Playgroud)

但是,在我的设备(iPhone 6s iOS 11.2)上,我收到以下内容..

2018-02-13 09:13:09.834879-0500 MY_APP[4327:313598] Tag scheme Language
2018-02-13 09:13:09.835256-0500 MY_APP[4327:313598] Tag scheme …
Run Code Online (Sandbox Code Playgroud)

locale objective-c ios ios-simulator nslinguistictagger

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

UIUserNotificationSettings警报导致应用程序退出活动

我目前有一个需要本地通知的应用程序,因此自然而然地我必须询问用户他或她是否想“允许通知”。这是我的做法:

AppDelegate.m

// Local Notifications
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];
    }
Run Code Online (Sandbox Code Playgroud)

在应用的初始加载中,我AVAudioPlayer开始播放了。我进行了设置,以便当用户离开应用程序(应用程序进入背景)时,音乐逐渐消失并暂停。

问题在于,在第一次启动该应用程序时,当弹出通知以要求用户允许通知时,该应用程序似乎被愚弄了,以为它将要退出活动。我似乎无法弄清楚如何要么避免JUST从触发这一通知警报,或在最坏的情况“带来的应用回来”,并成为活跃,一旦警报与的2个通知选项之一驳回。

这是我ViewController要在应用程序更改状态时通知我的内容:

ViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    ...

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseAudio)
                                                 name:UIApplicationWillResignActiveNotification object:nil];
    ...
}
Run Code Online (Sandbox Code Playgroud)

如果有人可以告诉我如何忽略通知警报,以使其不认为将要退出活动,或者在“退出”后如何将应用程序带回。我目前有其他尝试将其恢复的其他通知句柄,但是在警报“使所有内容变满”之后未调用它们:

(在同一ViewControllerviewDidLoad

...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(animateLoginScreen)
                                                 name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumeAudio)
                                                 name:UIApplicationDidBecomeActiveNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

感谢您对此提供的任何帮助。谢谢!

notifications objective-c avaudioplayer ios appdelegate

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