我不明白何时使用AnyObject以及何时在Swift中使用Any.
在我的情况下,我有一个字典
[String:???]
??? :可以是Int,Double,Float,String,Array,Dictionary
有人可以解释我和AnyObject之间的区别,以及在我的情况下使用哪一个.
奥洛克
我尝试使用 Vision (VNRequest) 中检测到的人脸的 boundingBox 裁剪 CVImageBuffer(来自 AVCaptureOutput)。当我使用以下方法绘制 AVCaptureVideoPreviewLayer 时:
let origin = previewLayer.layerPointConverted(fromCaptureDevicePoint: rect.origin)
let size = previewLayer.layerPointConverted(fromCaptureDevicePoint: rect.size.cgPoint)
Run Code Online (Sandbox Code Playgroud)
将边界框矩形转换为 previewLayer 坐标,一切都按预期工作。但是当我尝试应用到 CVImageBuffer(大小不同)时,结果是错误的。
下面你可以看到我如何转换返回的边界框的坐标以及我如何裁剪 CVPixelBuffer
class ViewController: UIViewController {
var sequenceHandler = VNSequenceRequestHandler()
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
// 1
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
// 2
let detectFaceRequest = VNDetectFaceLandmarksRequest(completionHandler: { [weak self] (request, error) in
guard error == nil else { return }
let cropedImage = self?.crop(request: …
Run Code Online (Sandbox Code Playgroud) 我想以编程方式使用imageView下的标题创建一个UIButton.
按钮大小:170*120图片大小:50*50标题大小:取决于文字.
我知道我要使用,但我不知道如何:
[_button setTitleEdgeInsets:UIEdgeInsetsMake(0.f, 0.f, 0.f, 0.f)];
[_button setImageEdgeInsets:UIEdgeInsetsMake(0.f, 0.f, 0.f, 0.f)];
Run Code Online (Sandbox Code Playgroud)
我想我应该计算标题的大小然后使用EdgeInsets.
谢谢.
几个小时以来,我一直试图弄清楚为什么autolayout在我应用CGAffineTransformMakeScale时在iOS8中突破了我的约束而在iOS7中没有.(我使用Xcode 6.0.1(6A317)与Storyboard和Autolayout).
代码 :
TCTGridController *gridController = self.gridController;
stackController.view.frame = gridController.view.frame;
stackController.stackCollectionView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[gridController.view.superview addSubview:stackController.view];
[UIView animateWithDuration:0.2 animations:^{
stackController.stackCollectionView.transform = CGAffineTransformMakeScale(1, 1);
[stackController.stackCollectionView layoutIfNeeded];
} completion:^(BOOL finished) {
[stackController didMoveToParentViewController:self];
}];
Run Code Online (Sandbox Code Playgroud)
iOS7结果:
iOS8结果:
iOS8上的约束错误:
(
"<NSLayoutConstraint:0x7fa126a9b100 V:[_UILayoutGuide:0x7fa126a9a900]-(120)-[TCTCollectionView:0x7fa125139400]>",
"<_UILayoutSupportConstraint:0x7fa126a8b500 V:[_UILayoutGuide:0x7fa126a9a900(0)]>",
"<_UILayoutSupportConstraint:0x7fa126a8a960 V:|-(0)-[_UILayoutGuide:0x7fa126a9a900] (Names: '|':UIView:0x7fa126a9a810 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa126c86840 h=--- v=--- 'UIView-Encapsulated-Layout-Top' V:[UIView:0x7fa126a9a810]-(0)-|>"
)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
奥洛克
ios ×2
swift ×2
apple-vision ×1
autolayout ×1
avfoundation ×1
image ×1
ios7 ×1
ios8 ×1
iphone ×1
storyboard ×1
text ×1
uibutton ×1
uiedgeinsets ×1
value-type ×1