小编sim*_*eon的帖子

基于视图大小的自适应UIPresentationController

我正在转向UIPresentationController我的视图控制器的基础演示,但是与API有些混淆.

我有一个自定义侧边栏样式视图控制器演示文稿(类似于LookInsideWWDC 2014演示代码).

此类集群(UIPresentationController,UIViewControllerTransitioningDelegateUIViewControllerAnimatedTransitioning)在常规大小类视图中将视图控制器显示为屏幕边缘的侧边栏,并在紧凑大小的类视图上呈现与全屏相同的视图控制器.

在可调整大小的iPad目标上进行测试显示正确的行为:我将水平尺寸类设置为"紧凑",我的视图控制器从侧边栏切换到全屏.

但是,我想要更多粒度.当设备处于横向时,我想在iPhone 6和6+上使用侧边栏式视图控制器演示,并且纵向使用所有iPhone的全屏风格演示.

所以在我的方法中

- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
Run Code Online (Sandbox Code Playgroud)

我实现了一些逻辑来检测侧边栏是否会占用太多屏幕,假设我使用以下条件:

//If my sidebar is going to occupy more than half the new width of the view...
if( self.sidebarTransitionController.width > size.width / 2.0 )
{
    //Override the presentation controller's trait collection with Compact horizontal size class
    sidebarPresentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
}
else
{
    //Otherwise override the trait collection with Regular
    sidebarPresentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];

}
Run Code Online (Sandbox Code Playgroud)

但这没有任何作用.UIPresentationController.overrideTraitCollection各州的文件: …

iphone ios8 adaptive-ui uipresentationcontroller uitraitcollection

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

SwiftUI @Binding 更新不会刷新视图

我觉得我缺少一些非常基本的东西,但是当单击按钮时,这个示例 SwiftUI 代码不会修改视图(尽管绑定更新)

我读过的教程表明这是使用绑定的正确方法,视图应该自动刷新

import SwiftUI

struct ContentView: View {
    @Binding var isSelected: Bool

    var body: some View {
        Button(action: {
            self.isSelected.toggle()
        }) {
            Text(isSelected ? "Selected" : "Not Selected")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    @State static var selected: Bool = false

    static var previews: some View {
        ContentView(isSelected: $selected)
    }
}
Run Code Online (Sandbox Code Playgroud)

binding swiftui

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

如何为着色器使用设计一个简单的GLSL包装器

更新:因为我马上就需要一些东西,所以我创建了一个简单的着色器包装器来完成我需要的东西.你可以在这里找到它:GitHub上的ShaderManager.请注意,它是为Objective-C/iOS设计的,因此对每个人都没有用.如果您对设计改进有任何建议,请告诉我们!

原始问题:

我是新手使用GLSL着色器.我对GLSL语言和OpenGL界面非常熟悉,但是我在设计一个简单的API时遇到了麻烦,通过它可以使用着色器.

用于与着色器交互的OpenGL C接口似乎很麻烦.我似乎无法在网上找到任何涵盖这类内容的API设计的教程.

我的问题是:任何人都有一个好的,简单的API设计或模式来包装OpenGL着色器程序API吗?

采用以下简单示例.假设我有一个顶点着色器,它只是模拟固定功能,还有两个片段着色器 - 一个用于绘制平滑矩形,另一个用于绘制平滑圆.我有以下文件:

Shader.vsh : Simple vertex shader, with the following inputs/outputs:
    -- Uniforms: mat4 Model, mat4 View, mat4 Projection
    -- Attributes: vec4 Vertex, vec2 TexCoord, vec4 Color
    -- Varying: vec4 vColor, vec2 vTexCoord

Square.fsh : Fragment shader for drawing squares based on tex coord / color
Circle.fsh : Fragment shader for drawing circles based on tex coord / color
Run Code Online (Sandbox Code Playgroud)

基本链接

现在使用这些的标准方法是什么?我是否将上述着色器链接到两个OpenGL着色器程序中?那是:

Shader.vsh + Square.fsh = SquareProgram
Shader.vsh + Circle.fsh = …
Run Code Online (Sandbox Code Playgroud)

opengl glsl wrapper ios

10
推荐指数
2
解决办法
6823
查看次数

自定义呈现的UIViewController更改为全屏

我有一个使用UIModalPresentationCustom演示风格呈现的视图控制器.我使用自定义UIViewControllerTransitioningDelegate将视图控制器显示为侧边栏(因此它从屏幕边缘滑入并且不占据整个屏幕).

然而,当我然后使用UIModalPresentationFullScreen- 然后关闭全屏视图控制器呈现另一个视图控制器时,我的基础自定义显示控制器突然调整大小以占据整个屏幕.有谁知道为什么会这样?

编辑:这本质上是我animateTransition提供侧边栏的方法 - 我已经删除了大部分代码以使其可读.基本上它从transitionContext获取容器,添加目标视图控制器的视图并将其设置为容器动画.

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIView *container = transitionContext.containerView;

    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *fromView = fromVC.view;
    UIView *toView = toVC.view;

    if( toVC.isBeingPresented )
    {
        [container addSubview:toView];

        //... Animate some new frame for toView            

        //Call [transitionContext completeTransition:YES] on animation completion
    }
    else
    {
        //... Animate fromView out

        //On completion remove fromView from superview

        //Call [transitionContext completeTransition:YES] on animation completion
    } …
Run Code Online (Sandbox Code Playgroud)

objective-c uiviewcontroller ios uimodalpresentationstyle presentviewcontroller

10
推荐指数
2
解决办法
3025
查看次数

将definePresentationContext与UIModalPresentationStyle.custom一起使用

我使用视图控制器包含来管理一组子视图控制器,它们应该能够以自定义方式模态地呈现其他视图控制器.

我遇到了一个问题,当视图控制器使用时,不使用definesPresentationContext属性UIModalPresentationStyle.custom

作为一个例子,我有三个视图控制器:ROOT,A,和B

ROOT
 |_ A
Run Code Online (Sandbox Code Playgroud)

A是的孩子ROOT.我想提出B的模态A,同时使用自定义UIPresentationController,UIViewControllerTransitioningDelegateUIViewControllerAnimatedTransitioning.

所以,我的里面的代码如下的控制器A(注控制器AdefinesPresentationContext设置true):

func buttonPressed(_ sender: Any?) {
    let presentationController = MyCustomPresentation()

    let controllerToPresent = B()

    controllerToPresent.modalTransitionStyle = .custom
    controllerToPresent.transitioningDelegate = presentationController

    present(controllerToPresent, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

但是,在我的演示控制器(也是我的UIViewControllerAnimatedTransitioning)内部,我遇到以下问题:

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    let fromVC = transitionContext.viewController(forKey: .from)
    let …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller ios uimodalpresentationstyle uipresentationcontroller

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

iOS App Bundle中的多个本地化.strings文件

我有一个相当复杂的项目,包括几个大型的本地化子项目.

我的大多数子项目都是通过一个Localizable.strings文件进行本地化的.此文件将复制到SubProjectName.bundle目标中,该目标与SubProjectName.a主项目中的静态库一起使用.这很好用.

但是,我的一个子项目包含许多本地化的.strings文件.无论设备(或模拟器)的配置方式如何,此项目都无法读取除英语之外的任何语言的字符串.

例如,这行代码始终返回英文字符串:

[[NSBundle myResourcesBundle] localizedStringForKey:@"MY_TEST_STRING" value:@"" table:@"MyTable"]
Run Code Online (Sandbox Code Playgroud)

其中MyTable对应于本地化为多种语言的MyTable.strings文件.当我查看.app包时,所有本地化都在那里,坐在应用程序内的"MyBundle.bundle"资源中.

但是,以下代码在所有本地化中正确查找给定字符串的翻译:

for (NSString *language in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"])
{
    NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle myResourcesBundle] pathForResource:language ofType:@"lproj"]];
    NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"MY_TEST_STRING", @"MyTable", bundle, nil));
}
Run Code Online (Sandbox Code Playgroud)

因此,当bundle是实际MyBundle.bundle/<LanguageCode>.lproj文件夹时,字符串查找起作用.但显然这违背了iOS提供的自动查找的目的.

(注意,[NSBundle myResourcesBundle]上面只是一个静态便捷方法来获取子项目的自定义包).

-

编辑:我一直在试验这个,如果我en.lproj从子项目的包中删除文件夹,那么它正确使用设备或模拟器的区域设置.

例如,我有:

MyApp.app/
 |
  - MyResources.bundle/
      |
       - en.lproj/
      |
       - zh-Hans.lproj/
Run Code Online (Sandbox Code Playgroud)

当我将模拟器(或设备)设置为简体中文时,它会查找字符串,en.lproj即使语言环境是zh-Hans.如果我删除en.lproj文件夹并重新启动应用程序,它会正确使用zh-Hans本地化.

localization uikit nsbundle nslocalizedstring ios

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

自定义 UITextInput 实现不显示多阶段输入建议

我有一个基于自定义UITextInput的文本编辑器。除了通过标记文本进行多阶段输入之外,它工作得很好。

我的标记区域渲染正确,并且插入了标记文本,但键盘上方的候选列表是空白的。

例如,下面是日语(假名)键盘,显示了有关标准 UITextView 的建议:

默认标记文本

这是我的自定义编辑器,显示相同的标记文本:

在此输入图像描述

我花了几天时间调试这个问题,发现原因是该方法UIKeyboardImpl返回私有类NOdelegateSupportsCorrectionUI

如果我在类别中覆盖此方法UIKeyboardImpl并返回YES,则多级输入建议会正确显示在我的文本编辑器中。然而,这并没有解决问题的根本原因(而且它不可用)。

我还仔细研究了 Apple 的 SimpleTextInput 示例代码。这实现了一个基本的核心文本编辑器。SimpleTextInput 正确显示多级输入建议,但是我似乎找不到其实现中的任何差异,UITextInput导致它工作而我的崩溃。

(事实上​​,我无法“破坏”SimpleTextInput 示例显示多阶段输入的能力。这让我认为我对实现的关注UITextInput是错误的。而且这完全是另一回事。)

cocoa-touch uikeyboard ios uitextinput uitextinputtraits

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

退格键为HELD Down时的UITextViewDelegate行为

我遇到了一个问题,当按住键盘上的Delete键时,iOS给我的UITextViewDelegate提供了不正确的信息。

当用户HOLDS在UITextView中的删除键在iPad中的UITextView将开始删除整个单词,而不是它被按下单个字符长(注:这不会发生在模拟器)。

发生这种情况时,UITextView委托方法:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
Run Code Online (Sandbox Code Playgroud)

被调用时,其范围包括正确的光标位置,但长度为1。这是不正确的,因为UITextView现在正在删除整个单词,而不是单个字母。例如,以下代码将只打印一个空格。

[textView substringWithRange:range]
string contains " "
Run Code Online (Sandbox Code Playgroud)

尽管UITextView删除了整个单词。替换文本正确指定为空字符串。是否有人知道解决此问题的方法或解决方法?

iphone cocoa-touch uitextview uitextviewdelegate ios

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