How to configure properties of UIScrollView - iphone

I want a UIScrollView in which i have to paste 25 images of same size(256*256).
The 13th picture should come in the centre,ie, when the app loades.
Then when i swipe right, left, up or down it should scroll as normally.
For doing this what should be the specifications of the UIScrollView,ie,
1.what should be its size
2.ContentViewSize
3.where should be its origin.

If your scrollView is going to be shown full-screen in portrait orientation, you should use the following sizes (assuming you don't hide the status bar):
UIScrollView frame: 320 x 460
contentSize: 8000 x 460 initial
contentOffset: (3840 , 0)

Related

Scroll View Content Width Change During Rotation (Autolayout) - Scroll View wrong size

I have a scroll view that has a content view inside of it.
The scroll view has constraints to the top, bottom, leading and trailing content view and top, leading, trialing superview with the bottom space to the bottom layout.
I change the Content View width on rotation:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
_contentWidth.constant = 480;
}else{
//iPhone Portrait
_contentWidth.constant = 320;
}
}
When I run the app and rotate to landscape, the width of the Content View changes and everything looks good, but the scroll view only allows scrolling on the left half of the screen (the whole view scrolls but your finger must be on the left side of screen to scroll). The Scroll View frame = (0 0; 320 431);.
If I go to another tab on my tab bar and return to this View the frame = (0 0; 480 320); what it is supposed to be and everything works/looks fine.
Any ideas what I need to do to get this by not selecting another tab and coming back?
EDIT
I made a subclass of Content View called ContentViewSubclass and put the following method in it:
-(CGSize)intrinsicContentSize{
CGSize size;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
size.height = 1000;
size.width = 480;
return size;
}else{
//iPhone Portrait
size.height = 1000;
size.width = 320;
return size;
}
}
Then on my ViewController.m I updated to the following code:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[_contentView invalidateIntrinsicContentSize];
[_contentView intrinsicContentSize];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{ _contentWidth.constant = 480;
_contentHeight.constant = 1000;
}else{
//iPhone Portrait
_contentWidth.constant = 320;
_contentHeight.constant = 1000;
}
}
When I log the sizes I get
Landscape:
ContentViewSubclass frame is (0 0, 480 1000)
UIScrollView frame is (0 20, 480 251)
contentView intrinsic size is {480, 1000}
Portrait:
ContentViewSubclass frame is (0 0; 320 1000)
UIScrollView frame is (0 20, 320 411)
contentView intrinsic size is {320, 1000}
Everything is in a Tab Bar View Controller and here is what it is set up like:
View
ScrollView
ContentView
Labels (many)
Textfields (many)
TableView (2)
CollectionViewSubcless (1)
I deleted the table views and Collection View in case they were causing problems and that didn't help.
Same issue. I get the correct layout on everything and it all scrolls, but you have be touching the left half of screen in landscape to scroll it. If I go to another tab view and return to this one it works correct. The scroll view then shows UIScrollView frame is (0 20, 480 300).
You're using the "Pure AutoLayout Approach" described here by Apple in a Technical Note: https://developer.apple.com/library/ios/technotes/tn2154/_index.html
The "Pure AutoLayout Approach" works in Apple's sample code because an image view has an intrinsic content size; your content view, on the other hand, does not.
If you don't want to switch to the "Mixed Approach", then your content view will have to have an intrinsic content size. You do that by creating a UIView subclass and overriding the intrinsicContentSize method. In the willRotateToInterface… method, send invalidateIntrinsicContentSize to your content view.
I struggled with a similar situation. In my case it was the rightmost section of the landscape screen-width which is "added" to the portrait screen-width when rotated to landscape (i.e. for all values of x where: w-h < x <= w). Buttons and such which were constrained to move into that area were there, but were unresponsive. If that sounds the same as what you're seeing, then this simple solution might help. It fixed it for me.

Why does my AQGridView not scroll when cell width is too high?

I implement the grid view cell size with this method:
- (CGSize)cellSize {
return _gridMode ? CGSizeMake(100, 100) : CGSizeMake(320, 345);
}
And check
_gridMode
for determining which cell to display (either a thumbnail or a full-screen cell).
The full screen cell is supposed to be 320x345.
It draws no subviews wider than 320px.
When I draw the full screen cell, I cannot scroll and when I switch back to grid mode, I see nothing (black screen).
When I set cellSize to 310x345 instead of 320x345, it works -- except my full screen subvies get offset by a few pixels horizontally.
What should I do to display full-screen width AQGridViewCells?

Disable right scrolling in uiscrollview in iphone

How can i disable left or right scrolling in scrollview in iPhone?
can any one give the code..
CGSize scrollableSize = CGSizeMake(320, myScrollableHeight);
[myScrollView setContentSize:scrollableSize];
You have to set the contentSize property of the UIScrollView. Like, if your UIScrollView is 320 pixels wide (the width of the screen), then you could do this
The UIScrollView will then only scroll vertically.
set your scrolview width 320. It will
like
[self.scrolview setFrame:CGRectMake(self.scrolview.frame.origin.x,self.scrolview.frame.origin.y,320,self.scrolview.frame.size.height)];

UIView width and height reversed

I have an iPad app and I'm having an issue in my rootViewController. I'm getting the wrong frame for it for some reason. The rotation works fine visually, but when I'm in landscape mode my width and height are reversed. Logging the frame I get the following:
Portrait: self view frame = {{0, 20}, {768, 1004}}
Landscape: self view frame = {{20, 0}, {748, 1024}}
That 20px for the status bar is moving as it should. But those values should be flipped. This view has a UIScrollView as a subview and it's frame is adjusting as it should. Has anyone come across this before?
If the width and height were reversed, the origin would then be wrong... I think this is the expected behaviour, as these coordinates are in the super view's system. What do you get with the bounds rectangle?

UIScrollView contentSize Issue - With example code

Within my view I create a scrollview with a width of 320 and a height of 70.
Responding to the user touching a button, I expand the scrollview, so it is 380(h) x 320(w) in size.
The code for this is shown below:
CGRect scrollviewFrame = CGRectMake(0, 30, 320, 380);
[scrollView setFrame:scrollviewFrame];
[self layoutScrollImages:YES];
CGSize srect = CGSizeMake([scrollView bounds].size.width, (kNumImages * (kScrollObjHeight + 10)));
[scrollView setContentSize:srect];
The constants mentioned in the above snippet are defined as:
const CGFloat kScrollObjHeight = 80;
const NSUInteger kNumImages = 100;
As I debug this project, I can see that srect is 320 (w) x 8000 (h) in size; however my issue is the scrollable area (where the user can actually touch to scroll the scrollview) remains the same as when it was it's original size.
I'm obviously missing something, does anyone know what it is?
have created a sample project to illustrate the issue I am having, it is available here: http://dl.dropbox.com/u/9930498/ScrollViewTest.zip
The problem in your sample is you have a very odd structure for loading your views. As such the view you're adding to the DetailScrollView instance is the root view of the DetailScrollView.xib, not the scrollview itself, which I believe is what you were expecting.
Fastest way to fix your problem is to adjust the root view in DetailScrollView.xib to autoresize width and height.
A UIView cannot respond to touches that are outside of the bounds of its superview. In your example, it appears that you expand the scroll view, but the scroll view's parent is still only 100 units high.
You should imagine the scrollView as a window, where by the window I mean the frame of the scrollView, which is also the coordinates that the scrollView detects your touches. By setting the contentView as 320 (w) x 8000 (h) you only change the content of the scroll view, which is the complete area behind that window.
By expanding content view, the scrollView can scroll a broader area, but in order to detect touches in a bigger rect, you should change frame of the scroll view.