小编Jos*_*son的帖子

在UIScrollView子视图中的UILabels上的UITapGestureRecognizer无法正常工作

我的UIScrollView内容视图中的UILabels上的UITapGestureRecognizer没有调用它的方法.

视图层次结构如下:

  • scrollView(UIScrollView)
    • contentView(UIView)
      • testLabel(UILabel) - 这里是附加UITapGestureRecognizer的地方

我已经将代码简化为一个示例以突出显示该问题

// Set scrollview size - Added in Storyboad
[scrollView setContentSize:CGSizeMake([arrayOfVerbs count]*self.view.frame.size.width, scrollView.contentSize.height)];
[scrollView setCanCancelContentTouches:YES]; // Tried both yes and no
[scrollView setPagingEnabled:YES];

// Add content view
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)];
[scrollView addSubview:contentView];

// Add test UILabel
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
[testLabel setBackgroundColor:[UIColor redColor]];
[testLabel setText:@"Test touch"];
[testLabel setUserInteractionEnabled:YES];
[contentView addSubview:testLabel];

// Add gesture recogniser
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playSound:)];
singleTap.numberOfTapsRequired …
Run Code Online (Sandbox Code Playgroud)

objective-c uiscrollview uilabel uigesturerecognizer ios

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

如何在Swift 3中将response.body从Vapor转换为String?

我正在使用Vapor尝试从另一台服务器获取XML文件,问题是我不知道如何将响应体转换为swift String.

let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")

let bodyBytes = bikesResponse.body
let string = String(bytes) // <-- WHAT DO I DO HERE?
Run Code Online (Sandbox Code Playgroud)

谢谢

vapor

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

是否可以更改iOS 8 Action Extension的视图大小?

我正在为iOS 8开发一个动作扩展.我希望视图是全屏的,它在iPhone上,但不在iPad上,在iPad上,我的扩展名在中间的小视图中显示.是否有可能使它在iPad上全屏显示?

操作扩展视图不占用iPad上的全屏大小

xcode6 ios8

6
推荐指数
2
解决办法
1181
查看次数

NSTextView 拖动带有自定义属性的文本

我的 NSTextView 子类有问题。我的视图包含具有自定义属性的属性字符串,因此我必须实现以下粘贴板方法以确保将我的自定义属性复制到粘贴板上。

writeSelection(to:type:)
readSelection(from:type:)
Run Code Online (Sandbox Code Playgroud)

在readSelection 中,我手动读取粘贴板上的字符串,并将其写入到NSTextView 的textStorage 中的rangeForUserTextChange。

override func readSelection(from pboard: NSPasteboard, type: String) -> Bool {


    // Manually reads the text on the pasteboard, and write it to textStorage

    if type == astroBoardAttributedString {

        if let string = pboard.string(forType: astroBoardAttributedString) {

            let attrString = NSAttributedString(string: string)

            self.textStorage?.replaceCharacters(in: self.rangeForUserTextChange, with: attrString)


            return true

        }


    }

    return super.readSelection(from: pboard, type: type)

}
Run Code Online (Sandbox Code Playgroud)

现在的问题是,当我选择并将文本从第 5 行拖到第 1 行下方时,文本会正确插入第 1 行下方,但是系统随后尝试从第 5 行原来所在的位置删除文本,该文本现在包含行4 因为在第 1 行下面添加了一个额外的行。

在此处输入图片说明

/*
line 1 <-- Drop …
Run Code Online (Sandbox Code Playgroud)

macos nstextview swift

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