Scroll while dragging with DragImage - objective-c

I'm trying to drag a view to another, I'm using DragImage method to pass data to my destination(another view), everything works fine, but while I'm dragging its container does not scroll.
the hierarchy:
NSWindow
NSScrollView
NSView -> NSScrollView's Document
NSViews -> NSView's subViews -> Drag and Drop between them.
I need to pass event
Any idea how to fix it?

Related

NSTextView does not scroll when created with NSCollectionView

I have an NSTextView that is on a view that is the view of an NSCollectionViewItem. I give the user the option to hide the NSTextView and instead bring up an NSView object in its place on the same view.
However, when I run the program with the NSView object hidden and overlapping the NSTextView, scrolling in the NSTextView does not work correctly; The vertical scroll bar is there and adjusts its size accordingly to the size of the content in the NSTextView. However, the actual scrolling only works by highlighting the NSTextView's content and dragging upwards or downwards. What's more is that if I recreate the view without it being connected to an NSCollectionViewItem and NSCollectionView, it scrolls fine. This is an issue that happens not just with the custom view I have overlapping the NSTextView, but with any view object (buttons, image wells, etc) that overlaps an NSTextView, even if the view object is set as hidden.
Why is scrolling only possible when highlighting and dragging upwards or downwards if the NSTextView is being created with NSCollectionView and there is a view object overlapping it?
Well, I have found a solution that makes little sense but seems to work fine. I subclassed NSTextView and overrode mouseEntered with this:
-(void) mouseEntered:(NSEvent *)theEvent {
NSScrollView *scrollView=(NSScrollView*)self.superview.superview;
NSScroller *scroller=scrollView.verticalScroller;
[scrollView setVerticalScroller:nil];
[scrollView setVerticalScroller:scroller];
}
If anyone has any idea as to why this issue is happening or a better solution and not just a guess-around, please post it

Remove a UIView from a UIScrollView and add to another custom UIView

I have a UIScrollView that contains a few custom UIViews that I can drag around by implementing the touchesMoved method. However, I need to be able to drag this custom view out of the scroll view and have it added to a custom UIView that is to function as a sort of dock for the view that is being dragged.
How would I go about implementing this? As soon as I remove the custom draggable view from its superview, it disappears (understandably). Thank you.
You have to have the view as a subview of the same view at the beginning and end of the drag.
In order to have it as a subview of another subview of this main view, you would have to destroy and recreate it at the appropriate place. You could do this both at the beginning and at the end of the drag process.

NSPopover cannot be dragged out

I have an NSPopover that contains an NSTabView which encloses all the popover's content view area. In this setup, I could not drag out the popover even though I've implemented detachableWindowForPopover: correctly in the delegate. I know I have implemented the delegate correctly because if the the tab view's size is reduced slightly (to uncover it's parent view), the popover can be dragged out into its own window.
Question is: How to make the popover can be detached by grabbing any blank area in the tab view?
Here's my object composition hierarchy
NSPopover
-> content view controller (NSViewController)
-> the content view controller's view (NSView)
-> NSTabView
-> (some other views and their controllers for each tab)

Only subviews added in viewDidLoad automatically resize

I've created a custom subclass of UIViewController that acts like a UINavigationController or a UITabBarController. Let's call it a ToolbarNavController. It has a toolbar at the bottom with controls for the user to move to a different content view.
I have two content views aside from the ToolbarNavController's view. Both are loaded from a nib and have their own controllers. The app starts out showing one of them. A button in the toolbar allows the user to switch between them.
When I add these views as subviews of the ToolbarNavController's views in viewDidLoad, they are correctly resized to fill the area between the status bar and the toolbar without overlap/underlap.
But when I try to lazy load the second view, adding it as a subview for the first time only when the user presses the toolbar button, iOS does not resize the view to account for the toolbar in its parent view, and it underlaps the toolbar which messes up my Autolayout constraints. Also, when I don't add the subview in viewDidLoad, if I put the device in landscape orientation before switching to the second view, it loads with a portrait orientation frame.
Bottom line: When inserting a subview in viewDidLoad, iOS sizes it correctly and manages autorotation for it. When inserting it later, I need to detect orientation set the frame myself. (And for some reason when I do this, autorotation kicks in again).
What is going on?
In viewDidLoad, the view is not yet layout for the resolution and interface orientation, and view properties are as they were in the interface designer. So, if you had a portrait view, that is how the initial properties of the view are set when going into viewDidLoad. When you add your view there, you add it to the XIB view. Later, iOS performs layout on the view hierarchy and thus resizes your inserted view as needed. But when adding your view at a later point, the view hierarchy has already been layout, so it is expected that the new view you are adding is also layout correctly.
Best practice is to calculate the size you need using the size of the view you are inserting into. For example, half the width of the containing view, or third the bounds, etc. This way it is independent on the orientation the interface is in.

Programmatically change subviews from within subview's controller

In my iPhone application I've set up a default, blank view called Main View into which various child subviews will be loaded for different parts of the application. It's the same approach as if I was using a tool bar to switch between subviews. That case, in the MainView controller I could hook IBActions to buttons in the toolbar, so that when a button was pressed, MainView added different subviews to itself.
In my situation, though, I need to tell MainView to change its subview from within the subviews. So here are two sister subviews, each with their own controller and xib, that would be loaded as subviews of MainView:
- StartView
- FormView
In StartView, after some animations and welcome stuff, a button triggers the camera image picker. Once the image picker returns the image, I need to tell MainView to remove StartView and add FormView.
It may be the result of a long day or my newness to iPhone OS but I'm stuck getting my head around the right way to set up my objects/controllers.
You never have more than one view controller active at a time. (The nav and tabbar controllers don't control views, they control other controllers.) In this case, you will have a single controller that has the MainView as its view property. It will add StartView and formView as subviews of MainView.
However, this is not a good design. It will overload the MainView controller by forcing it to juggle many views. It would be better to use a hidden navigation controller or a tabbar. Hierarchies of controllers can create the illusion from the users point of view for almost any interface layout you can imagine. There is no need to create a logical structure that mimics the visual one.
From your description you may only need a single view/view-controller pair: Set the formView controller to open the camera view before it displays the formView. When the camera is dismissed it reverts to the formView automatically. No fuss, no muss.