Problem using NSView's scrollRect:by:
Problem using NSView's scrollRect:by:
- Subject: Problem using NSView's scrollRect:by:
- From: Tae Won Ha <email@hidden>
- Date: Wed, 25 Jan 2017 23:13:47 +0100
Hi guys.
I'm trying to implement a view that has scroll functionality by itself,
since I cannot use an NSScrollView. I think that NSView's scrollRect:by:
is probably the way to go, but how can I use it? I tried the following
(in a freshly created Xcode project):
AppDelegate.swift:
--- >8 ---
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
fileprivate let testView = TestView(frame: CGRect(x: 0, y: 0, width:
400, height: 400))
// This is invoked by a menu item created and linked in the xib file.
@IBAction func triggerScroll(_: Any) {
self.testView.scroll(CGRect(x: 0, y: 0, width: 50, height: 50), by:
CGSize(width: 100, height: 100))
}
func applicationDidFinishLaunching(_: Notification) {
self.window.contentView?.addSubview(self.testView)
}
}
class TestView: NSView {
override func draw(_ dirtyRect: NSRect) {
NSColor.red.set()
NSRectFill(CGRect(x: 0, y: 0, width: 50, height: 50))
}
}
--- 8< ---
What I expected was that the red box at the bottom left corner gets
'copied' to the point (100, 100) when I invoke the triggerScroll action.
However nothing happens. What am I doing wrong?
Thanks in advance and best,
Tae
PS. Other possible solution seems to be to use a CGBitmapContext to draw
stuff into it and, when scrolling, to draw a clipped version of it at
the right location, but it seems to be a quite overkill (if the above
would work...)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden