NSScrollView resize automatically - objective-c

I have a NSScrollView, which I would like to resize automatically.
I would send a method to it's documentView to get the size of it, like in a table view I would calculate and return the required size of the rows.
My problem is, when?
How can I figure out if the documentView of the scroll view has been resized?
Has anyone an idea how to do this?
Which methods do I have to override?
I'll publish the project on Github if I figure it out.

Any NSView or a subclass will call -viewWillStartLiveResize and -viewDidEndLiveResize when resizing begins and ends.
NSView Class Reference
Or, if you're interested in knowing when the window is resized:
Stack Overflow: get window height/width in real-time

Related

Is there a function to know the useableSize of a view?

It must take into account:
statusBar (which can be 40 points if you have hot spot)
TabBar
NavigationBar.
Basically at viewDidLoad I see that my view has a size of 320*480.
I wonder where did iOS decide that as the screen size of my screen. I use UIStoryBoard.
So, on viewDidLoad, I intended to resize that.
I am not even sure if this is the right approach.
Note: the issue I am facing doesn't seem to happen if I do not use storyBoard.
At viewDidLoad, when I use XIB, the content of self.view is correct, namely 416, instead of 480, due to UInavigationController and UITabBar
Try overriding the UIViewController viewWillLayoutSubviews method. The view's frame will be set by then.
In the viewWillLayoutSubviews method, the view controller's main view is the size you need to know. It has been adjusted for status bars and nav bars and tools bars and tab bars. It also takes into account orientation. There is no single method where you can ask what the size will be. Besides, there is no need to ask such a question. Create all the subviews you want in viewDidLoad. But lay them out based on the view's size in viewWillLayoutSubviews.

UIWebView redraw on rotate

I have implemented a UIWebView object into a custom UIView (TSAlertView). My UIWebView sits in the middle of the UIView, as a subview.
When I rotate the iOS device screen, the UIWebView object redraws right on top of the old one, without deleting the old one. All the other elements of this custom UIView are destroyed and redrawn when the screen is rotated.
I imagine I must have missed some sort of procedure for deallocating resources or removing the UIWebView from view. I have tried adding 'autorelease' to the declaration of the UIWebView, but to no avail. I wonder if this is a common symptom of a simple oversight I have made in the way the UIWebView is created?
This seems to be a simple case of not telling the UIWebView object it should destroy itself before it is redrawn on each rotate - but I don't know how I can go about this...
Any wisdom gratefully received.
Ideally while rotating you should not create the views again. Instead you can rearrange the frame in delegates appropriately. In your case you might be creating a UIWebView again, which should be avoided. Instead of that, you can keep it as a class level param(Declare in .h file) and adjust the frame in delegate methods for rotation. Also please note that release/autorelease wont remove your view from superview. You need to call removeFromSuperview method to achieve that.
Check this for view resizing and layout handling

NSScrollView incorrect content size

I have an NSScrollView that is the parent of a custom NSView subclass. The subclass uses the NSScrollView's contentSize method in order to layout its subviews.
The issue is that upon first launch, NSScrollView reports the contentSize wrong. It reports the size as being 15px more than it should be (the width of the scroller). So it seems to me that it is returning the contentSize without taking into account the scroller width; however, as soon as I adjust the frame of the scroll view (by resizing, etc.) the content size is reported properly. It seems to be just a problem upon initial launch.
Should this be reported as a bug, and are there any good solutions to this? I could use the dirty way of performing a check during layout to see if its the first time the method has been called, and then deduct 15px from the content size, but if there's something better, that would be appreciated.
I just came across a similar problem and the way I solved it was to observe the notification NSViewFrameDidChangeNotification on the Scroll view's content view (in your case the custom NSView).
This notification gets triggered when a scrollbar is added/removed from the scroll view, at which point you can reposition your view's content.
When are you checking the content size? Is it happening as your view is being instantiated from the nib file, or after the nib has been fully unarchived?
What I would probably do is invoke your layout method from -viewDidMoveToWindow: or -awakeFromNib
Are you using the option to hide/show automatically the scrollbars?

Looking for guidance on detecting overlap of UIImageViews

The scenario is that I have a UIViewController containing multiple "InteractiveUIImageViews" (inherited from UIImageView) each containing their own UIImage. In InteractiveUIImageView I have iplemented methods for touchesBegan, touchesMoved and touchesEnded to handle their movement and behaviour on screen. Certain objects of this type will be set as 'containers' (think recycle bin) with the objective being that when one image is dragged onto it, it will be removed from the screen and placed inside it to be potentially retrieved later.
My current thinking would be to call a new method in UIViewController from the touchesEnded method of my InteractiveUIImageView but being new to all this I'm not really sure how to go about doing that (e.g. calling a method from the 'parent') or indeed if this is the best way to achieve what I want to do.
Thanks in advance for any advice.
I'm afraid your question is (too me at least) a bit unclear. I get that your are trying drag a UIImage around a scene and drop it in drop-locations.
What is unclear is you class hierarchy. I believe that you are going about it in a wrong way. You shouldn't have to subclass UIImage at all.
Instead I would urge you to let the UIViewController manage the movement of the images. When you touch down on an image, you also touch down on its parent (containing) view.
What you have to to is then reposition the UIImage (all handled by the UIViewController) as you drag the image across the screen. When you let go you check if your finger was inside your drop-zone on touch up.

UIImageView on top of another UIImageView, changeing layers

Afternoon, I have a UIImageView that I progmatically add to the window. Infact I have multiple UIImageViews that do so and when I click on any specific UIImageView I want it to become 'top-dog' so to say and be drawn over all other objects on the screen. Basically like the priority drawing for MSWindows operating systems when it comes to their windows. I've scoured all the options built in for UIImageViews when it comes to layering but I cannot seem to find any! I know it exists because in UIBuilder there is a command for sending back/front toBack/toFront. How do I access these progmatically?
Edit*
Also I fear that you might have to access the order in which the subViews are pushed into the 'subView stack' and manually move these around to achieve the result that I want and if so, how would I go about doing this?
Edit2*
Perhapse these are the functions I'm looking for?
bringSubviewToFront
sendSubviewToBack
exchangeSubviewAtIndex
Does this allow for easy Index shuffling?
UIView class has bringSubviewToFront: and sendSubviewToBack: for changing subviews z-order (see "Managing the View Hierarchy" section in class reference for more).