前提:我正在构建一个裁剪工具,可以处理图像的两指任意旋转以及任意裁剪。
有时,图像最终会以插入空白空间的方式旋转,以填充旋转图像和裁剪矩形之间的间隙(请参阅下面的示例)。
我需要确保图像视图在旋转时完全适合裁剪矩形。如果没有,我需要重新转换图像(缩放)以使其适合裁剪范围。
使用这个答案,我实现了检查旋转的 UIImageView 是否与裁剪 CGRect 相交的功能,但不幸的是,这并没有告诉我裁剪矩形是否完全包含在旋转的图像视图中。希望我可以对此答案进行一些简单的修改?
OK 的直观示例:

不好,我需要检测和处理:

更新:不起作用的方法
- (BOOL)rotatedView:(UIView*)rotatedView containsViewCompletely:(UIView*)containedView {
CGRect rotatedBounds = rotatedView.bounds;
CGPoint polyContainedView[4];
polyContainedView[0] = [containedView convertPoint:rotatedBounds.origin toView:rotatedView];
polyContainedView[1] = [containedView convertPoint:CGPointMake(rotatedBounds.origin.x + rotatedBounds.size.width, rotatedBounds.origin.y) toView:rotatedView];
polyContainedView[2] = [containedView convertPoint:CGPointMake(rotatedBounds.origin.x + rotatedBounds.size.width, rotatedBounds.origin.y + rotatedBounds.size.height) toView:rotatedView];
polyContainedView[3] = [containedView convertPoint:CGPointMake(rotatedBounds.origin.x, rotatedBounds.origin.y + rotatedBounds.size.height) toView:rotatedView];
if (CGRectContainsPoint(rotatedView.bounds, polyContainedView[0]) &&
CGRectContainsPoint(rotatedView.bounds, polyContainedView[1]) &&
CGRectContainsPoint(rotatedView.bounds, polyContainedView[2]) &&
CGRectContainsPoint(rotatedView.bounds, polyContainedView[3]))
return YES;
else
return NO;
}
Run Code Online (Sandbox Code Playgroud) 我正在编写几个采用不同类型参数的函数。这样,只需执行以下操作即可:
var myFunc = function() {
var args = Array.prototype.slice.call(arguments)
}
Run Code Online (Sandbox Code Playgroud)
...而不是尝试直接在函数声明的参数字段中处理所有不同的可能性,例如:
var myFunc = function(param1, param2, param3) {
if (param3) {
// etc.
}
}
Run Code Online (Sandbox Code Playgroud)
Array.prototype.slice.call(arguments)不过,这会增加代码很多,并降低了可读性。我试图弄清楚是否有一种方法可以编写一个可以完成与相同功能Array.prototype.slice.call()但更简洁易读的辅助函数。我正在尝试类似的东西:
var parseArgs = function() {
return Array.prototype.slice.call(arguments)
}
var foo = function() {
console.log(parseArgs(arguments))
}
foo('one', 'two', 'three')
// [Arguments, ['one', 'two', 'three']]
Run Code Online (Sandbox Code Playgroud)
但这显然行不通。
使用 Node.js v5.1.0,我试图确定缓冲区的内容长度。因此,我正在这样做:
Buffer.byteLength(self.data, 'utf8')
Run Code Online (Sandbox Code Playgroud)
其中,self.data如下所示:
<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 f0 00 f0 00 00 ff db 00 43 00 05 03 04 04 04 03 05 04 04 04 05 05 05 06 07 0c 08 07 07 07 07 0f 0b 0b 09 ... >
Run Code Online (Sandbox Code Playgroud)
我正在加载的图像在文件系统 (OS X) 上为 109,055 字节(磁盘上为 111 KB),但我的内容长度计算返回了 198,147 字节。如果我将编码设置为ascii,它将返回 104,793 个字节。更接近,但仍然不正确。
我计算正确吗?我需要对缓冲区做些什么才能让它返回正确的值吗?如果我做对了,为什么会出现差异?如果我做错了,好吧,请分享;)
我的视图有一个表视图,每行都有一个集合视图。集合单元格有一个文本字段(及其子类)、一个标签和一个文本视图,它们都是全尺寸的,并且除了一个之外的所有单元格都根据单元格位置隐藏。
当编辑其中一个文本字段时,委托 (CollectionView) 将新值传递回视图控制器以更改数组,然后重新加载适当的单元格,因为其中有计算数据。
问题是第二次编辑其中一个文本字段时,两个单元格交换宽度,如果您再编辑文本字段两次,似乎会交换回来,但边框仍处于错误的位置。
初始加载后的表:

两次改变数量后的表格

文本字段和视图委托方法
func textFieldDidEndEditing(_ textField: UITextField) {
let currencyField = textField as! CurrencyField
let indexPath = indexPathForCellWithSubview(cellSubview: textField)!
(dataSource as! DetailViewController).changeData(tableRow: tag, collectionItem: indexPath.row, newData: currencyField.decimal)
let indexPaths: [IndexPath] = [IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0),IndexPath(row: 4, section: 0),IndexPath(row: 5, section: 0)]
collectionViewLayout.invalidateLayout()
reloadItems(at: indexPaths)
}
func textViewDidEndEditing(_ textView: UITextView) {
let indexPath = indexPathForCellWithSubview(cellSubview: textView)!
let indexPaths: [IndexPath] = [IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0),IndexPath(row: 4, section: 0),IndexPath(row: 5, section: 0)] …Run Code Online (Sandbox Code Playgroud) 在 TypeScript 中,我们能够根据对象的键创建“文字”类型:
const tastyFoods = {
pizza: '',
burger: '',
iceCream: '',
fries: '',
taco: '',
sushi: '',
spaghetti: '',
donut: '',
cookie: '',
chicken: '',
} as const;
type TastyFoodsKeys = keyof typeof tastyFoods;
// gives us:
// type TastyFoodsKeys = "pizza" | "burger" | "iceCream" | "fries" | "taco" | "sushi" | "spaghetti" | "donut" | "cookie" | "chicken"
Run Code Online (Sandbox Code Playgroud)
Python 中是否有等效项(3.10+ 可以)用于基于字典创建类型提示?例如,
from typing import Literal
tasty_foods = {
"pizza": '',
"burger": '',
"iceCream": '',
"fries": '', …Run Code Online (Sandbox Code Playgroud) 我正在处理Sails.js上的文档,并根据他们的"入门"指南创建了一个基本的dev实例:
$ sudo npm -g install sails
$ sails new testProject
$ sails generate users
$ sails lift
Run Code Online (Sandbox Code Playgroud)
这四个简单的命令将安装平台,创建项目,并按users设计创建模型.
在我的浏览器中,使用默认安装端口,我现在可以按预期访问http://localhost:1337/users和接收空的JSON数组[].
现在,如果我想创建一个新用户,REST最佳实践要求我应该使用该POST方法.POST确实有效,但开箱即用,Sails 还允许您执行GET http://localhost:1337/users/create生成新的用户对象.
通过阅读他们的文档,我无法确定一种限制允许哪些HTTP方法执行各种任务的方法.这是在文档中吗?或者有人可以解释在Sails堆栈中哪些(应该)可以管理?
PHP中的模式意味着什么:
'#^/abc/(?P<abc>[^/]++)$#si'; // please expand this pattern's meaning.
什么是字符串可以匹配这种模式preg_match_all?
我需要将宽度的CSS属性设置为与浏览器当前宽度相同的大小.为此,我做了var setWidth = $(window).width(),但我不知道如何将其应用于我当前的代码,这是这样的:
$(document).ready(function(){
$("#backgroundImg").css("width", "");
});
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?我是JQuery的新手,所以我可能真的很业余.
我正在使用child_process.spawn并且需要捕获命令失败时发生的 shell 错误。根据这个问题,我应该能够做到:
var child_process = require('child_process');
var python = child_process.spawn(
'python', ["script.py", "someParam"]
);
python.on('error', function(error) {
console.log("Error: bad command", error);
});
Run Code Online (Sandbox Code Playgroud)
当我用 替换'python', ["script.py", "someParam"]时banana,就像在链接的问题中一样,它可以工作,并且错误是可见的。但在我的情况下,使用带参数的 python,永远不会调用 'error' 事件。
如何从python捕获shell错误?
UIRefreshControl使用一个非常大的微调器:

我想调整它的大小(旋转器的框架,而不是下拉长度!)看起来更像这样:

我在参考文档中看不到有关如何做到这一点的任何内容,虽然它继承自UIView,但设置框架不起作用(可能是因为我正在使用AutoLayout?)
let refreshControl = UIRefreshControl()
refreshControl.frame = CGRect.init(x: 0, y: 0, width: 32, height: 32)
Run Code Online (Sandbox Code Playgroud) ios ×3
javascript ×3
node.js ×3
swift ×2
buffer ×1
css ×1
html ×1
jquery ×1
objective-c ×1
php ×1
python ×1
regex ×1
sails.js ×1
type-hinting ×1
types ×1
typescript ×1