• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Auto Layout and Resizable NSViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Auto Layout and Resizable NSViews


  • Subject: Re: Auto Layout and Resizable NSViews
  • From: Thomas Wetmore <email@hidden>
  • Date: Mon, 20 Jul 2015 19:41:42 -0400

Quincey,

Thanks. I’m using Xcode Version 6.4 (6E35b). Mac running 10.10.4. Programming in Swift 1.2.

Here is the mouse-down method with event loop. As you can see I am calling setFrameOrigin in the dragging case and setting frame directly in the resizing case.

override func mouseDown (event: NSEvent) {
        var resizing = false
        var dragging = false
        let clickLocation = convertPoint(event.locationInWindow, fromView: nil)
	if resizePath.containsPoint(clickLocation) { resizing = true }
	else { dragging = true }
	// Remain in an event loop until left mouse up.
        let mask = NSEventMask.LeftMouseUpMask | NSEventMask.LeftMouseDraggedMask
        var lastDragLocation = superview!.convertPoint(event.locationInWindow, fromView: nil)
        while resizing || dragging {
            let event = window!.nextEventMatchingMask(Int(mask.rawValue))
            if event == nil { continue }
            if event!.type == NSEventType.LeftMouseUp {
                resizing = false
                dragging = false
            } else if event!.type == NSEventType.LeftMouseDragged {
                let dragLocation = superview!.convertPoint(event!.locationInWindow, fromView: nil)
                if dragging {
                    var origin = frame.origin
                    origin.x += dragLocation.x - lastDragLocation.x
                    origin.y += dragLocation.y - lastDragLocation.y
                    setFrameOrigin(origin)
                    needsDisplay = true
                } else if resizing {
                    var origin = frame.origin
                    var size = frame.size
                    origin.y += dragLocation.y - lastDragLocation.y
                    size.height -= dragLocation.y - lastDragLocation.y
                    size.width += dragLocation.x - lastDragLocation.x
                    frame = CGRect(origin: origin, size: size)
                    needsLayout = true
                    needsDisplay = true
                }
                lastDragLocation = dragLocation
            }
        }

Tom Wetmore

> On Jul 20, 2015, at 4:43 PM, Quincey Morris <email@hidden> wrote:
>
> On Jul 20, 2015, at 13:30 , Thomas Wetmore <email@hidden> wrote:
>>
>> When I instantiate one of these views and place it in an NSWindow, I can drag it around and I can resize it, as expected. Notably, however, I can resize it down to zero size (and even smaller!), even though the two constraints exist. I kind of expected the program to crash when the constraints were violated, but things keep on running. I can drag and resize the view at will with no repercussions.
>
> a. What version of Xcode are you using?
>
> b. What mechanism are you using (inside the mouse-down event loop) to change the size?
>


_______________________________________________

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


  • Follow-Ups:
    • Re: Auto Layout and Resizable NSViews
      • From: Quincey Morris <email@hidden>
References: 
 >Auto Layout and Resizable NSViews (From: Thomas Wetmore <email@hidden>)
 >Re: Auto Layout and Resizable NSViews (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Drag highlight problems
  • Next by Date: Re: Auto Layout and Resizable NSViews
  • Previous by thread: Re: Auto Layout and Resizable NSViews
  • Next by thread: Re: Auto Layout and Resizable NSViews
  • Index(es):
    • Date
    • Thread