- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有 CALayer 的 NSView (myImage),内容 = NSImage,因此 View 的大小现已调整为完全适合 NSImage(大小未知且可能会更改)。这是在另一个 NSView (myContainer) 内,该 NSView 被固定以独立地在两个轴上扩展和收缩。
所以我希望它的行为就像 NSImageView 设置为“按比例缩小”。在调整大小时在“myContainer” View 的范围内保持完全可见,并且永远不会大于我将 NSImage 添加到其 CALayer 时创建的大小。
仅在 IB 中可能吗?不确定,但即使混合了 IB 创建的约束以及应用程序运行时生成和修改的约束,我也无法像 NSImageView 那样工作。请帮忙。
编辑有进展func newUserImageInputDidArrive() -> Void {
// the real widh and height of the NSImage we will add to layer of NSView
currentImageRealWidth = (mainImageDropZone.image?.size.width)!
currentImageRealHeight = (mainImageDropZone.image?.size.height)!
// set the width of NSView to match above
mainImageView.frame.size.width = currentImageRealWidth
mainImageView.frame.size.height = currentImageRealHeight
// create the layer in the NSView
mainImageView.wantsLayer = true
mainImageView.layer?.borderColor = NSColor.redColor().CGColor
mainImageView.layer?.borderWidth = 5
// so the image added to the layer will resize proportionately within the bounds of the layer
mainImageView.layer?.contentsGravity = kCAGravityResizeAspect
// add the image
mainImageView.layer?.contents = mainImageDropZone.image
// so now NSView's layer has the image and is the size of the origonal image
}
带有该层的 NSView 目前在所有方面都固定到其 super View 。这给了我与“按比例向上和向下缩放”中的 NSImage View 相同的行为。但我只想“按比例缩小”。所以我觉得我必须限制 NSView 的宽度和高度,该 NSView 将图层保持为从图层中使用的原始图像检索到的最大宽度和高度。但如何实现这一点正在暗示我。
最佳答案
解决了最后一 block 拼图。加上我的问题中上面的代码:(currentImageRealWidth 在用户添加图像时存储为变量)。
override func viewWillLayout() {
if(mainImageView.layer != nil){
if(mainImageView.layer?.frame.width > currentImageRealWidth){
conMainImageViewLeading.constant = (mainContentView.frame.width - currentImageRealWidth) / 2
conMainImageViewTrailing.constant = (mainContentView.frame.width - currentImageRealWidth) / 2
}else{
conMainImageViewLeading.constant = 0
conMainImageViewTrailing.constant = 0
}
}
super.viewWillLayout()
}
关于swift - 布局约束使 NSView 的行为类似于 NSImageView 中的 NSImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36875206/
我有一个 NSTableView,它包含所有 NSImageView 的名称,并且根据 NSImageView 的添加顺序,最后一个将位于前面。 但是如果我希望用户能够将 NSImageViews 放
我有一个 NSImageView 可以很好地作为图像运行。它也是通过绑定(bind)的。使用值路径属性显示每个记录的已保存图像的值转换器(值转换器只是附加文件路径——我只是将图像的文件名存储在数据库中
我想在 NSImageView 中捕捉图像变化的事件,我该怎么做? 最佳答案 您可以尝试使用 KVO监视image键。如果这不起作用,您可能必须继承 NSImageView 并将逻辑插入到 setIm
我创建了 NSImageView 的子类,因为我想自定义一些 mouseClick 事件。但是,我还没开始,就出了问题。我创建了 NSImageView 子类: (文件/新建/文件.../Cocoa(
所以,我的 Cocoa 应用程序中遇到了这个奇怪的问题。一个工具栏项,和一些 NSImageViews 只是渲染他们的图像颠倒,没有明显的原因。当我出于某种原因启动应用程序时,工具栏项目实际上是这样的
我是Mac开发新手,我们有类似的方法吗 imagev = [NSArray arrayWithObjects 我需要一些类似于我们在 iOS 中所做的事情想要在 mac 中做的事情, imageVie
任何人都可以给我推荐一个在 NSImageView 中缩放图像的好示例代码吗?谢谢。 最佳答案 如果你看the documentation ,你会发现 NSImageView 不支持这一点。使用Ima
我有一个 Cocoa 应用程序。在窗口 View 中我放置了一个 NSImageView。使用自动布局,我添加了前导和尾随空格,使得 NSImageView 锚定到 View (以及窗口)。 NSIm
目前我想创建一个圆角NSImageView,我是新手,怎么做? 最佳答案 我不知道这是否有效,所以请尝试一下,我们会祈祷的。在 iPhone 上,您可以使用任何 UIView(iOS 中的 NSVie
所以我习惯了UIImageView ,并能够设置其图像在其中显示的不同方式。例如 AspectFill模式等... 我想使用 NSImageView 完成同样的事情在 Mac 应用程序上。是否NSIm
我有一个使用以下代码的 iOS 应用程序。我现在正在为 Mac OS X 创建应用程序并希望获得相同的效果,但是我似乎无法使用 clipsToBounds .我应该使用什么? 我有其余的代码在 Mac
我正在玩 AppKit 和 NSDocument,但我不知道为什么这不起作用?: 我刚刚写了这个,图像不是零,但从不加载任何图像,它的大小始终为零。 这是我必须实现的正确方法才能将文件读入我的文档吗?
我的 Mac 应用程序中有一些 NSImageView,用户可以在其中拖放 .png 或 .pdf 等对象,将它们存储到用户共享默认值中,这很好用。 我现在想在用户双击这些 NSImageView 时
我是 OS X 编程的初学者,在设置 NSImageView 透明度时遇到问题。 在 iOS 中这很简单,在 UIImageView 中有一个名为 alpha 的属性,我可以更改它并为其设置动画。 (
我如何能够在 Objective C 中屏蔽 nsimageview?例如,有一个带圆角的 nsimageview。 最佳答案 你不知道。如果你想以 NSImageView 不支持的方式绘制图像,则需
出于某种原因,分配两个 NSImageView 会造成巨大的内存泄漏。 尽管 dealloc 方法在两个 NSImageView 中都会被调用。 我正在使用ARC。 使用NSImageViews 一旦
我正在尝试制作一个简单的双骰子游戏。在过去的一年里,我完成了大量的 C 编程,并且正在尝试转换为 GUI 和 Obj C。我的窗口内有一个按钮和两个图像单元。图像被视为输出(染料、染料2),按钮保持
我有多个不同尺寸和比例的 NSImageView,它们垂直堆叠在水平空间有限的 View 中。 由于图像尺寸可能大于父 View 的尺寸,我想使用 NSImageScaleProportionally
我已经 Hook 了 NSTableView 的选择更改事件。我需要在 ImageView 中显示所选图像 func tableViewSelectionDidChange(_ notificatio
我创建了一个 NSView 的自定义子类来控制 2 个 NSImageView。创建图像的代码如下: - (id)initWithFrame:(NSRect)frameRect AndMap:(NSI
我是一名优秀的程序员,十分优秀!