Scroll Disabled on setting scroll frame size again - iphone

Hello friends i am very new to ios.
I am setting scroll size in view did load as
scrollView.frame=CGRectMake(0, 0, 320, 460);
[scrollView setContentSize:CGSizeMake(320,500)];
now i want to scroll my frame up on clicking on button.
scrollView.frame=CGRectMake(0,-100, 320,550);
my frame moves up but after this my scroll view is disabled i also tried using scrollview enabled but it also not works.
please suggest me Thanks in advance for your ans.

Because second time you're setting
scrollView.frame=CGRectMake(0,-100, 320,550);
in which 550 is height of scrollView and it is greater than its content height as you have set
[scrollView setContentSize:CGSizeMake(320,500)];
If you want to move your scrollView frame up on clicking on button then just decrease its Y co-ordinate dont increase its height. For vertical scrolling content height should be greater than frame height.
So second time set frame like this -
scrollView.frame=CGRectMake(0,-100, 320, 460);

You set [scrollView setContentOffset:animated:] instead of setting frame to scroll. Ref
In your case, you can probably do
[scrollView setContentOffset:CGPointMake(0, 100) animated:YES];

Related

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)];

UINavigationBar and UIScrollView resizing

I've UIViewController with navigation bar and scrollview within it.
When scrollview scrolls down I hide navigation bar and set bounds for scrollview to fit free space.
self.navigationController.navigationBarHidden = YES;
[scrollView setBounds:CGRectMake(0, 0, 320, 411)];
Height is 411 cos there is also UITabBarController.
But scrollview doesn't fit whole view. When I check it's frame it says that frame = (0 22; 320 411); How could I fix that?
I've tried to use setFrame function instead of setBounds. Also I dont need to resize it's content I need to change its frame.
i think you use setFrame and also setContentSize if needed here...
its may be happen because off its content size not manage after your scrollview bounds are changed...
hope this help you....
:)
I believe you need to set the frame of the scrollview.
scrollView.frame = CGRectMake(0, 0, 320, 411);
The bounds is a coordinate system in relation to the view and not its containing view.
Try to use setFrame function.
[scrollView setFrame:CGRectMake(0, 0, 320, 411)];

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.

Image scroller problem

hello every buddy
i want to make horizontal image scroller at bottom view and in the back of side big Image View. i don't know how to make image horizontal scroll.
Place the image view inside a scroll view whose horizontal content size is greater than its frame width, i.e.
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = CGRectMake(0, 0, 100, 100);
scrollView.contentSize = CGSizeMake(300, 100);
[scrollView addSubview:imageView];
You should use contentSize property of the UIScrollView to set its content size according to your requirement and then set the property showsHorizontalScrollIndicator to YES and showsVerticalScrollIndicator to NO . But you don't require to set these two if you set frame and content size properly. Like if _myScrollView.frame.height and _myScrollView.contentSize.height is same then you don't need to set horizontal and vertical scroll. Its vertical scroll will automatically be disabled.
you can use scroll view with page control for a horizontal slideshow. follow the tutorial it might help you
http://www.edumobile.org/iphone/iphone-programming-tutorials/pagecontrol-example-in-iphone/

How to reduce the size of uiscrollview from top

I am creating a music application in which I am adding a scrollview to uiview, and another view is without scrollview. I want to reduce the size of scrollview from top. When I reduce the size of scrollview it gets reduced from bottom and that is a problem.
This is my code for scrollview:
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,360)];
[[self view] addSubview:scroll];
[scroll setScrollEnabled:YES];
[scroll setBounces:NO];
[scroll setAlwaysBounceHorizontal:NO];
First the size of scrollview was 320,400 I reduced it by 40 and made it to 360 and so it get reduced from bottom. I want it should get reduced from top. How it is possible?
Well, if you reduce the size of the view but you want the bottom to remain at the same coordinate you just need to adapt the y coordinate accordingly as in:
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,40,320,360)];