How to make only vertical scroll view? - three20

I already read this one:
http://api.three20.info/interface_t_t_scroll_view.php
But it seems like there is no property for vertical scroll only. However based on the:
http://three20.info/gallery
There are few apps that has "vertical-scroll-only" apps, like the facebook apps. In the facebook app, you can keep vertically scroll to view the latest status/posts/images from your friends, I was wondering if they use TTScrollview or UIScrollview.
Whats the correct way of displaying the "vertical-scroll-only" view in Three20 framework?
Please advise, thanks !

Facebook is most likely using TTTableView for displaying the status updates view in the Facebook app.
TTTableView inherits UITableView, which only scrolls vertically.
Whether you're using Three20 or not, a simple way to implement a vertical only scroll view is to use UIScrollView.
To make a UIScrollView "vertical-scroll-only" you would set the width of the contentSize property to less than or equal to the width of your scroll view, while its height needs to be greater than your scroll view's height to allow for vertical scrolling.
UIScrollView *yourScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
yourScrollView.contentSize = CGSizeMake(320, 210); // <-- sets the scrollable area
yourScrollView.backgroundColor = [UIColor grayColor];
[self.view addSubview:yourScrollView];

Related

UIScrollView without AutoLayout shows horizontal scroll Indicator in iOS 6 but not in iOS 7

I spent several days trying to see the working UIScrollView horizontal scroll indicator (without AutoLayout) on iOS7 (on iPad). But without success.
Has anyone fixed such bug?
My project is simple and running iOS5 and iOS6 without troubles.
I found out, that on iOS7 height of the scroll indicator image is always zero:
UIImageView * scrollBar = [[scrollView subviews] lastObject];
if (scrollBar != nil)
{
PrintRect(#"FRAME", scrollBar.frame);
PrintRect(#"BOUNDS", scrollBar.bounds);
}
Result for iOS7:
FRAME x:0.000000 y:54.000000 w:338.000000 h:0.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:0.000000
but for iOS6:
FRAME x:0.000000 y:47.000000 w:338.000000 h:7.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:7.000000
So the height scroll bar image on iOS7 is equal to zero.
It's possible to change the height, but only for a quick time because during drugging the height becames zero again.
I was stuck on something similar. I am doing the CS193P course on iTunes and there was this scrollView exercise - Imaginarium. Basically it's just a UIImageView embedded in a UIScrollView. I was having the same problem that the scroll indicators were not being displayed (with Autolayout turned off)
I looked up the header file for UIScrollView in the documentation and there is this property in scrollView called scrollIndicatorInsets:
The distance the scroll indicators are inset from the edge of the scroll view.
#property(nonatomic) UIEdgeInsets scrollIndicatorInsets
It goes on to say that the default value is UIEdgeInsetsZero!! So I created a UIEdgeInset using UIEdgeInsetsMake (see documentation). Then in viewDidLoad I set this UIEdgeInsets to be my scrollView's scrollIndicatorInsets, after which my indicators appeared when I scrolled.
Hope this works for you too.

Floating UIView on UITableView broken in iOS6

In my app i have UIView that floats at the top of a UITableView (Visualise:Attached to the bottom of the navigation Bar), under iOS5 i was enabling it to float at the top using these lines of code in scrollViewDidScroll
// get the table and buttonView bounds
CGRect tableBounds = self.tableView.bounds;
CGRect buttonViewFrame = self.buttonView.frame;
// make sure the buttonView at the table's original x and y as the content moves
self.buttonView.frame = CGRectMake(tableBounds.origin.x,tableBounds.origin.y,buttonViewFrame.size.width,buttonViewFrame.size.height);
This however no longer seems to work in iOS6, does anyone know why or how to fix the problem? I'm supporting iOS5 and above.
Having looked through the iOS6 release notes i found this...
Note that you can make a subview of the scroll view appear to float (not scroll) over the other scrolling content by creating constraints between the view and a view outside the scroll view’s subtree, such as the scroll view’s superview.
How would I set this up in code as Im not using AutoLayout in storyboards as I'm still supporting iOS5. It would also be great if anyone can enlighten me as to why the code i was using in iOS5 no longer works in 6.

Autoresize the root view when device is rotated

I am developing PDF reader. I am facing problem while rotating the simulator. What I am doing is, when view is loaded by the ViewController(i.e. in the loadView), I am creating the UIScrollView which contains UIImageView and UIView of the same size(i.e. size of the PDF page). It is working perfectly in the portrait mode. But when I rotate the simulator in the landscape mode, the view is not autoresized according to device. I have tried
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
in the viewDidLoad() of the ViewController
But it's not working. I am confused how the above two properties work. I guess these properties will autoresize the UIScrollView to the size of root view in which I am loading UIScrollView. But what should be done to autoresize the main view in which UIScrollView is loaded??
I've experienced the same problem when trying to utilise the auto resizing methods. So, I hope this will help. (P.S. I'm assuming you're creating the UI programmatically and not via IB)
So have you tried this?
Inside your viewcontroller add the following:
// Set the View Controller to fit the whole screen.
-(BOOL)wantsFullScreenLayout{
return YES;
}
Inside the loadView method amend your scrollView to:
// set the initial size of your scrollView object.
[scrollView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
// Set the auto resizing attributes.
[scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
In addition to this you might need to set the autoresizingmask margins for either the UIView or UIImageView depending on the type of layout you require when the device is rotated.
This is late reply... It may help if you didn't Fix it yet.
When you create any app in portraid mode and if you want it to rotate (resize) to landscape mode, you should do it in User Interface Builder or .xib (or in Storyboard iPad or iPhone)file.
So to check or to check rotate in the Simulator:
Go to "USER INTERFACE BUILDER", or ".XIB" (or "Storyboard iPad or iPhone") file.
Then select "UIImageView" and go to "SHOW THE ATTRIBUES INSPECTOR".
In the fourth tab (Attributes Inspector) set the mode to “Aspect Fit”, and in the third tab (Size Inspector) and in the fifth tab (Size Inspector) set the autosizing attributes to the following:
Set the arrows to all directions. Sorry can't load image.
Do the same for "UIView" (3).
Before you move on, you can double check that you’ve gotten all of the autosizing attributes right by selecting the Detail View Controller, and changing the orientation from Portrait to Landscape: Sorry can't load image for now...
You can Check or Change to "Landscape or Portrait" on the top right side "Simulated Metrics" select under "Size" the "Orientation".
If something isn’t right, don't worry: Just change it back to Portrait and double check the settings.

Selectable area for NSButton

So I am basically trying to make a list of selectable text items (just a list of text, no button bezels, backgrounds, etc.). I suppose that I could make this happen with an NSTableview, but trying to make the table view completely transparent and still functional was giving me some issues. Anwyays, I am trying to do it with NSButtons that I create programatically and add to my view in a list, without any background or bezel. However, when I set the properties to make the button transparent and without bezel, the clickable area of the button is relegated to the text of the title of the button alone. Clicking anywhere else that the button should be (around the title) no longer works. Here is the code I am using. I want to be able to click anywhere in the rect in which I create the button in order to cause a click. FYI I have tried NSSwitchButton without the checkbox image and it is the same thing. Thanks for your help!
for(NSString *theTask in theTasks){
NSButton *theCheckBox = [[[NSButton alloc] initWithFrame:NSMakeRect(xCoordinate + 25, yCoordinate + ([tasksWindow frame].size.height/2) - 60, [tasksWindow frame].size.width - 40, 25)] autorelease];
[theCheckBox setButtonType:NSToggleButton];
[theCheckBox setAction:#selector(taskChecked:)];
[[theCheckBox cell] setBackgroundColor:[NSColor clearColor]];
[[theCheckBox cell] setBordered:NO];
NSAttributedString *theTitle = [[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:#"%#", theTask] attributes:[NSDictionary dictionaryWithObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName]] autorelease];
[theCheckBox setAttributedTitle:theTitle];
[[tasksWindow contentView] addSubview:theCheckBox];
yCoordinate -= 20;
}
UPDATE: I've been able to confirm that setting the background color to clear is what seems to cause the button to stop responding to clicks within its full boundaries (not the removal of the border).
So to answer my own question, it was because I was overlaying the transparent buttons atop a transparent NSWindow (which refuses mouse events). I simply had to set the window NOT to ignore mouse events and the behavior went away.

Using NSScrollView with CALayer

I'm attempting to create a grid style view (similar to NSCollectionView), except using Core Animation. I'm pretty far through it, and the last major thing left to do is implement scrolling.
My setup so far is that I have an NSView subclass (layer backed), and upon initialization it creates and adds the grid layer as a sublayer of the main view layer. I have created a custom CALayoutManager for the grid layer that arranges its subviews in a grid-like formation. As expected, when I add sublayers to the grid layer, the layout manager is called and the layers are positioned automatically. Up to this point, everything is working as it should.
The problem comes when I try to use an NSScrollView as a parent of my custom view to implement scrolling. I set this up as follows: I created my custom view as a subview of the NSScrollView in Interface Builder. Then, in my layout manager class, I added a delegate property and during initialization, my view subclass sets itself as the delegate of the layout manager. At the end of the layoutSublayersForLayer: method of the layout manager, I call upon its delegate with the delegate method layoutManager:contentHeightChanged:. Here is the implementation of that method in my NSView subclass:
- (void)layoutManager:(MyLayoutManager*)manager contentHeightChanged:(CGFloat)height;
{
CGFloat newHeight = [[self enclosingScrollView] contentSize].height;
if (height > newHeight) {
newHeight = height;
}
NSRect newFrame = [self frame];
newFrame.size.height = newHeight;
[self setFrame:newFrame];
}
It's pretty simple, it just checks to see whether the new height is larger than the content size of the scroll view, and sets the views frame with the new height.
This works — to a certain extent. When the view resizes, it sizes the view's frame properly as it should to encapsulate the full height of the content, thereby making scrollbars appear. The problem: the sublayers of the grid layer jitter when the view is being resized with the scrollbars visible. Here's a video showing the problem:
http://vimeo.com/16987653
As you can see, there is no issue when the scrollbars aren't visible (in other words, when the height of the content fits within the bounds of the scroll view). I can confirm that this isn't a problem with the layout manager and dealing with single columns, because I tested the same thing without the scroll view and there are no jitters.
Any advice is greatly appreciated.
Solved this problem by flipping the coordinate system of both the layer and the view (origin at top left corner).

Resources