Change the height of NSScroller in NSScrollView - objective-c

I have a NSScrollView, which has NSClipView and vertical/horizontal NSScrollers in it.
Now I want to change the height of the vertical scroller so that it occupies only the top half portion of the scroll view. I can not change the height from the size inspector. I tried changing the frame. It didn't work either.
Can someone help me get through this problem? Thankyou in advance!

Since OS X 10.10, NSScrollView has a scrollerInsets property which should be able to position the scroller differently than the scroll view itself, if wanted.

Small world.
I ended up cooking a special component for the 8th pure SwiftUI/FRP incarnation of WhatSize.app
There are things Swift UI can't really do, so you have to wrap NSView objects as NSViewRepresentable and now they are available to a pure SwiftUI app.
scrollView.scrollerInsets = .init(top: 0.0, left: 0.0, bottom: 14.0, right: 0.0)
So the vertical scroll bars do not stomp over the drag and column resize icon on the bottom in yellow.
This allows WhatSize to display data just as Finder's "as Columns" does.

Related

NSFullSizeContentViewWindowMask and title/toolbar height?

I am attempting to implement something similar to Safari where the window's style mask is set to NSFullSizeContentViewWindowMask so the NSToolBar and title bar blur the background view.
This works fine, however I have a view that I need to not be clipped by the toolbar/titlebar, similar to how Safari's WebView has an initial top padding that doesn't cover the content when the view is unschooled.
My attempted solution was to create a dummy NSView which the unclipped views align their top value to, then changing the height constant of the dummy view to the height of the titlebar/toolbar. The issue, however, is that there seems to be no way to calculate the height of the toolbar.
This suggests that I calculate the height by subtracting the height of the contentView from the height of the window, but that only works (returns 0 otherwise as the two heights are equal) if I don't use NSFullSizeContentViewWindowMask which I want to use for the blurring effect.
Am I overlooking something simple, or is there no simple way to accomplish this?
Check NSWindow's contentLayoutRect property.

iOS7 - Get UIView's useful height (excluding statusBar, navigationBar and tabBar)

Introduction
This is a rather common question, however I have certain extra points to observe. One of them is that I don't want to make my bars opaque. I like the iOS7 translucent bars.
I have an UIImageView inside a UIScrollView, and I'm trying to set the initial scrollView.zoomScale to fit the image in the screen just like the stock Photos app does. That means: the image should not be cropped and should fill the screen as much as possible.
However for my app this is a bit more complicated as I have visible statusBar, navigationBar and tabBar. I will adopt the solution to hide them until the user touches the screen, but I'm still curious for a solution when hiding is not desirable.
Done so far
I'm currently calculating the zoom based on a relation between the image's height and the view's height:
double heightRelation = self.image.size.height / self.view.frame.size.height;
After applying 1/heightRelation to the scrollView.zoomScale, the image is still bigger than the useful space. Then I found the iOS7 default heights for statusBar (20pt), tabBar (49pt) and navigationBar (44pt) from the documentation and also from:
NSLog(#"status : %f", CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]));
NSLog(#"tab : %f", self.tabBarController.tabBar.frame.size.height);
NSLog(#"nav : %f", self.navigationController.navigationBar.frame.size.height);
... and after playing a little, I found that the exact combination would be to subtract statusBar and navBar heights from the view's height:
double heightRelation = self.image.size.height / (self.view.frame.size.height - CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) - self.navigationController.navigationBar.frame.size.height);
This works great for the Portrait mode, but doesn't for Landscape. I know I could also make a condition to set the zoom according to the orientation but... The code is probably getting unnecessarily ugly.
So I ask you: what's the best method to get the useful height?
P.S.: Interface Builder's option "Adjust Scroll View Insets" has no effect.
Don't use the bars directly. Use the length properties of bottomLayoutGuide and topLayoutGuide of the view controller to determine how much of the view is "wasted" under the bars. These take into account navigation bars, toolbars, status bar, tab bars, etc., and are maintained by the system when the bars are resized (for example, after rotation to landscape on phone/pod idioms).

Autoresize Height and Width Proportionally Interface Builder

I have a UIImageView that is set to autoresize it's height based on the height of the Superview, i.e. when the In Call Status bar comes down. How do I make the entire view resize proportionally so that the width of the UIImageView changes when the height changes?
I would like to do this in Interface Builder, but programmatically can be used as well.
Thanks
The easiest way in iOS 6 is to use the (new in iOS 6) autolayout feature. It is very easy to make a view's width always be a fixed proportion of its height.
Otherwise you'll have to detect the change in your view controller's layoutSubviews and use code to resize the UIImageView.
However, consider the alternative of letting image resize rather than the whole image view. If you give the UIImageView the right contentMode, it will automatically resize the image proportionally if the view's height changes.

xcode 4.5, iPhone 5 breaks my UIScrollView

So I've got a pretty complex project. I'm using both interface builder and xcode directly to build objects. Right now I have UIScrollViews being built in IB, where they need to be, and UIButtons built on top of those scrollviews. There are several scrollviews in the same spot, but that really shouldn't make much of a difference.
Anyway, the issue is that it works perfectly on the iPhone 4. But when building on the iPhone 5, it moves the Scrollviews to the bottom of the screen, where before it was x=0, y=361. All my other objects are being placed correctly with some empty space underneath them. I know how to check for iPhone 5:
I don't know how to post code on here with colors and whatnot, they make it super complicated so here is how I'll do the if/then:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480){
// iPhone Classic
}
if(result.height == 568){
// iPhone 5
}
}
I don't know of a way to do if/then in IB. I tried just manually changing the location this way:
[peopleScrollView scrollRectToVisible:CGRectMake(0, 449, 320, 58) animated:NO];
That did not work. So, what I'm asking is there a way to change the location of a UIScrollView in the code itself? If there is not, then I think I will have to build all 5 UIScrollViews manually in code, which I definitely do not want to do.
If you select your Scroll View object, then click the Size Inspector module, you will notice the default Autosize Mask is set to: Left, Top.
Depending on your view "Mode" option, and your view's "Resize Subviews Automatically" option, this view and subviews will be shifted down on the 4" screen compared to the 3.5" screen.
Depending on what your particular view should look on each screen is up to you. On my project, I adjust the autosize mask to Left, Top, and Bottom,
as I want my UIScrollView and subviews to remain at the top of the screen (as drawn in IB) on the 3.5" and 4".
You can also set vertical and / or horizontal sizing arrows inside the box in the autosize graphic
. This will attempt to scale object as accordingly for dynamically sized screens.
The Autosize Mask should be your new best friend with iPhone5.
See Xcode Interface Builder. How Do These Autosizing Mask Settings Differ? for more info.

Disabling scrolling when image is zoomed

I have an image inside a UIScrollView. What I want to happen is if I zoomed in to a particular position, I want to disable the scrolling (both vertical and horizontal) so that it will remain on the zoomed area. Can you give me any ideas on how to do this?
Two things to keep in mind:
Make sure you are exactly where you want when you need to disable the scroll. (you can use some methods from the UIScrollViewDelegate to accomplish that).
Make the contentSize of your UIScrollView the same size of your frame. This way both the horizontal and the vertical scroll will be disable.
CGRect myScrollViewRect = myScrollView.frame;
CGSize myScrollViewFrameSize = CGSizeMake(myScrollViewRect.frame.size.width, myScrollViewRect.frame.size.height);
myScrollView.contentSize = myScrollViewFrameSize;
For clarity I putted more code than you would normally need to.