小编bra*_*ipt的帖子

为什么\ b在python re模块中不起作用?

众所周知,这\b意味着正则表达式中的单词边界.但是repython中的以下模块代码不起作用:

>>> p=re.compile('\baaa\b')
>>> p.findall("aaa vvv")
[]
Run Code Online (Sandbox Code Playgroud)

我认为返回的结果findall应该是["aaa"],但它没有找到任何东西.怎么了?

python regex

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

用于UITextView文本的iOS 8 sizeThatFits未返回正确的高度(AutoLayout)

我正在尝试使用从中检索的适当高度垂直居中UITextView sizeThatFits.有许多其他答案表明这是计算这个的最合适的方法.

(请注意,我已经尝试使用普通字符串和属性字符串,并且两者都发挥相同的行为).

无论我尝试什么(即使使用属性字符串并将字体大小或行高设置为更大或更小的东西),它总是只显示一定截断数量的文本字符(在这种情况下,3行,它总是完全相同) ).我错过了什么?

_textView.text = [_collectionDescription lowercaseString];
_textView.font = [UIFont fontLight:22];
_textView.textColor = [UIColor whiteColor];
_textView.textAlignment = NSTextAlignmentCenter;
_constraintTextViewHeight.constant = ceilf([_textView sizeThatFits:CGSizeMake(_textView.frame.size.width, FLT_MAX)].height);

[_textView setNeedsDisplay];
[_textView updateConstraints];
Run Code Online (Sandbox Code Playgroud)

objective-c uitextview ios autolayout nslayoutconstraint

9
推荐指数
1
解决办法
2万
查看次数

将presentModalViewController与故事板一起使用

我对iOS编程很新,我正在开发一个iPad应用程序,它附带一个带有4个视图控制器的Tab键控制器(名为FirstViewController,SecondViewController等).目前,标签栏控制器设置为应用程序的默认起点.我希望能够在用户到达该点之前对其进行身份验证,因此我添加了另一个名为LoginViewController的View Controller,它在Storyboard中自行浮动.

我想要做的是允许应用程序加载和在didFinishLaunching中,显示登录页面,直到身份验证完成,然后关闭它.过去几天我一直在寻找,但我一直在尝试的一切都失败了.

我最近的尝试是

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];

UINavigationController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];

loginVC.modalPresentationStyle = UIModalPresentationFullScreen;

[self.window.rootViewController presentModalViewController:loginVC animated:YES];
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.它编译并运行,但视图根本没有出现,我真的很困惑为什么会发生这种情况.

authentication objective-c storyboard presentmodalviewcontroller ios

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

如何将Photoshop的水平调整映射到核心图像过滤器?

我将几个photoshop元素映射到CIFilter,唯一一个我遇到麻烦的是这个级别调整:

从当前版本的photoshop拍摄的屏幕截图

哪个CI过滤器(或过滤器的组合)将允许我在第一个示例中使用上面的16,1.72,239和39/245或者在第二个示例中使用31,1.25,255 30/255.我相信这是一种阴影/黑白水平调整.

任何帮助赞赏.

iphone photoshop core-image ios

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

Node.js:如何禁用chunked transfer-encoding?

我在content-length节点服务器的响应中缺少一个标题,我正在从另一个位置输出.zip文件.我content-length通过下面的代码注入了一个标题,但似乎仍然transfer-encoding: chunked以某种方式覆盖它.

响应标题

HTTP/1.1 200 OK
access-control-allow-origin: *
connection: close
content-type: application/zip
date: Mon, 14 Jul 2014 03:47:00 GMT
etag: "\"eb939974703e14ee9f578642972ed984\""
last-modified: Sat, 12 Jul 2014 02:15:52 GMT
server: Apache-Coyote/1.1
set-cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Sun, 13-Jul-2014 03:47:00 GMT
transfer-encoding: chunked
X-Powered-By: Express
Run Code Online (Sandbox Code Playgroud)

var request = require('request');
var express = require('express');
var async = require('async');

var app = express();

app.get('/:bundle_id?', function(req, res) {
    var bundle_id = req.params.bundle_id;
    bundle_id = bundle_id.replace(/\.zip$/, '');

    var url = …
Run Code Online (Sandbox Code Playgroud)

http-headers node.js express

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

在滚动视图内缩放旋转图像以适合(填充)叠加矩阵的帧

通过这个问题和答案,我现在有了一种检测何时任意旋转的图像不完全在裁剪矩形之外的工作方法.

下一步是弄清楚如何正确调整它包含滚动视图缩放,以确保裁剪矩形内没有空格.为了澄清,我想放大(放大)图像; 作物直肠应保持未转化.

布局层次结构如下所示:

containing UIScrollView
    UIImageView (this gets arbitrarily rotated)
        crop rect overlay view
Run Code Online (Sandbox Code Playgroud)

... UIImageView也可以在scrollView中进行缩放和平移.

有4个手势事件需要考虑:

  1. 平移手势(完成):通过检测它是否被错误地平移并重置contentOffset来完成.
  2. 旋转CGAffineTransform
  3. 滚动视图缩放
  4. 调整裁剪矩形覆盖框架

据我所知,我应该能够使用相同的逻辑2,3和4来调整滚动视图的zoomScale,以使图像正确匹配.

如何正确计算使旋转的图像完全适合裁剪矩形所需的缩放比例?

为了更好地说明我想要完成的任务,这里是一个不正确大小的示例:

在此输入图像描述

我需要计算必要的缩放比例,使它看起来像这样:

在此输入图像描述

这是我到目前为止使用的Oluseyi解决方案的代码.当旋转角度很小(例如小于1弧度)时,它可以工作,但除此之外的任何东西都会变得非常不稳定.

CGRect visibleRect = [_scrollView convertRect:_scrollView.bounds toView:_imageView];
CGRect cropRect = _cropRectView.frame;

CGFloat rotationAngle = fabs(self.rotationAngle);

CGFloat a = visibleRect.size.height * sinf(rotationAngle);
CGFloat b = visibleRect.size.width * cosf(rotationAngle);
CGFloat c = visibleRect.size.height * cosf(rotationAngle);
CGFloat d = visibleRect.size.width * sinf(rotationAngle);

CGFloat zoomDiff = MAX(cropRect.size.width / (a + b), cropRect.size.height / (c + d)); …
Run Code Online (Sandbox Code Playgroud)

objective-c uiscrollview cgaffinetransform ios

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

当指向使用Cocoapods的github仓库时,有没有办法指定子文件夹?

我正在使用一个repo的fork,它包含一个更大的项目和一个子文件夹中的SDK.podspec有一个source_files配置子文件夹的属性,但顶级repo不知道podspec,因此指向:

pod 'PodName', :git => 'https://github.com/owner/project.git'
Run Code Online (Sandbox Code Playgroud)

...失败,因为根目录中没有podspec.有没有办法在将Cocoapods指向git repo时指定使用子文件夹?

就像是:

pod 'PodName', :git => 'https://github.com/owner/project.git', :subfolder => '/subfolder/path/to/podspec'
Run Code Online (Sandbox Code Playgroud)

ios cocoapods

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

在TTTAttributedLabel中指定多个/条件链接颜色

我在TTTAttributedLabel中添加了一个链接检测器,用于标识@mentions和#hashtags,并在我的TTTAttributedLabel实例中的该位置创建一个链接:

- (void)highlightMentionsInString:(NSString *)text withColor:(UIColor *)color isBold:(BOOL)bold isUnderlined:(BOOL)underlined
{
    NSRegularExpression *mentionExpression = [NSRegularExpression regularExpressionWithPattern:@"(?:^|\\s)(@\\w+)" options:NO error:nil];

    NSArray *matches = [mentionExpression matchesInString:text
                                                  options:0
                                                    range:NSMakeRange(0, [text length])];
    for (NSTextCheckingResult *match in matches) {
        NSRange matchRange = [match rangeAtIndex:1];
        NSString *mentionString = [text substringWithRange:matchRange];
        NSRange linkRange = [text rangeOfString:mentionString];
        NSString* user = [mentionString substringFromIndex:1];
        NSString* linkURLString = [NSString stringWithFormat:@"user:%@", user];
        [self.attributedLabel addLinkToURL:[NSURL URLWithString:linkURLString] withRange:linkRange];
    }
}
Run Code Online (Sandbox Code Playgroud)

我还发现我可以轻松更改链接颜色和属性:

NSArray *keys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName
                             , nil];
NSArray *objects = [[NSArray alloc] initWithObjects:color,[NSNumber numberWithInt:kCTUnderlineStyleNone], nil]; …
Run Code Online (Sandbox Code Playgroud)

objective-c ios tttattributedlabel

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

从另一个脚本运行Node Package + Arguments

我发现自己处于一种情况,我必须运行一个命令,例如 node compile.js

该.js文件需要运行以下命令

browserify -t jadeify client/app.js -o bundle.js

安装了所有依赖项,通过在CLI中运行此命令可以正常工作,只需要弄清楚如何在节点脚本中执行它.

我们还在package.json里面包含了类似的内容

"script" : [ "compile": "browserify -t jadeify client/app.js -o bundle.js" ] 当你cd /project && npm run compile通过ssh 执行而不是通过exec 执行时,这非常有效

谢谢

node.js browserify

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

iPhone 6s - iOS 9.1崩溃[UICollectionViewController previewingContext:viewControllerForLocation:]

这是一个非常愚蠢的堆栈跟踪,因为环顾四周,我唯一能想到的是iPhone 6s用户试图3D触摸某些东西,我的手势识别器(某处,我不知道哪一个,因为它没有告诉我哪条线甚至哪个控制器都不知道如何处理它?我没有添加任何3D触摸手势识别器,也没有在任何地方实现3D触摸交互.

我已经在这个版本中针对iOS 8,并且我没有iPhone 6s进行测试,不幸的是它无法真正重现它.

关于可能导致它的原因的思考,如何缩小何处/什么以及如何重现,以及如何处理异常?

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x18586cf48 __exceptionPreprocess
1  libobjc.A.dylib                0x19ad17f80 objc_exception_throw
2  CoreFoundation                 0x185873b54 __CFExceptionProem
3  UIKit                          0x18b63438c -[UICollectionViewController previewingContext:viewControllerForLocation:]
4  UIKit                          0x18b187d7c -[_UIViewControllerPreviewSourceViewRecord previewInteractionController:viewControllerForPreviewingAtPosition:inView:presentingViewController:]
5  UIKit                          0x18b43cd4c -[UIPreviewInteractionController startInteractivePreviewAtLocation:inView:]
6  UIKit                          0x18b43d848 -[UIPreviewInteractionController startInteractivePreviewWithGestureRecognizer:]
7  UIKit                          0x18b43e8c0 -[UIPreviewInteractionController _handleRevealGesture:]
8  UIKit                          0x18b37b330 _UIGestureRecognizerSendTargetActions
9  UIKit                          0x18afa4b5c _UIGestureRecognizerSendActions
10 UIKit                          0x18ae3285c -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:]
11 UIKit                          0x18b37c70c ___UIGestureRecognizerUpdate_block_invoke898
12 UIKit                          0x18adf18b8 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks
13 UIKit                          0x18adee63c _UIGestureRecognizerUpdate
14 UIKit                          0x18ae306cc -[UIWindow _sendGesturesForEvent:] …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios 3dtouch

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