Restricting a UISCrollView to scroll up - iphone

I have a custom view covering entire screen in iPod touch. I need to put add another view in this which will initially be hidden but will come on screen when view is scrolled down. I hav achieved this but not I can scroll my view to upside also. I so not want user to pull up the custom view. I just want a pull down feature and no pull up.
When someone pull down I am bringing the view to original position programatically. So, when user pull down they can see some information for 5 secs and then view is back to original position.
Hoe can I restrict my UIScrollView from being scrolled towards up on manual interaction?

I did this by following code. Its working now.
(void)scrollViewDidScroll:(UIScrollView *)iScrollView {
// Refrain the view from scrolling up
if (iScrollView.contentOffset.y > 0.0) {
iScrollView.contentOffset = CGPointZero;
}
}

Related

Disable all superviews except a specific view

I have UIView that open with a UIButton click. I want to disable user interaction of all other superviews except to this specific view and his subviews, how can I do that? Just to make this view the only view that will response to user touch.
Thanks!
Agree with the comment, you probably want to disable all siblings of a view... (edited so you can set them back to enabled at some point)
- (void)setSiblings:(UIView *)view enabled:(BOOL)enabled {
for (UIView *sibling in view.superview.subviews) {
if (sibling != view) sibling.userInteractionEnabled = enabled;
}
}
I know you already accepted an answer but a better (and easier) approach is to display the new view full screen. Make the new view with a clear background. Then add the real view as a subview to this full screen view. This way you don't have to mess with any existing views to display this new view. You can still see everything behind it but touch events are blocked by the clear, fullscreen view.
Then when you remove this full screen view (fade out animation?) you don't have to mess with all the existing views again.
You shouldn't have to modify existing views just to display another. And what happens if one of those existing views really should have its interaction disabled? You will end up enabling the interaction when you dismiss your "modal" view.

How to implement pull right to fresh while pulling the last page of a scrollview?

How to implement pull left to fresh while pulling the last page of a scrollview? i want mimic the popular pulling down to refresh.
Pull down to refresh was done (wrongly) adding a subview to a table view, and monitoring the scroll content offset of the scrollview (table view extends scrollview). I say wrongly, because you can add a tableHeader to do the same thing instead of adding it as a subview.
You need to do it by adding other subviews to your scrollview and then monitoring the scroll offset, the same as what I've just mentioned above.
Look at the methods of UIScrollViewDelegate to see all the different callbacks you get from UIScrollView interaction. It's very versatile.

Gain control over scroll view

I have a scroll view which contains several objects like text fields,labels,switch etc..Now as we are aware that a table view by default provides control for user to scroll and stop where ever he/she wishes to.Like wise I want to achieve the same control for scroll view to stop any where at any point of the view.But my scroll view is not behaving properly,It is not stopping when scrolling is in progress.In other words scroll view is lacking smooth behavior.Instead it is scrolling to the extreme end and showing the 2nd half of view or it is appearing as if it is scrolling and its making the view unchanged i.e. to the start point and showing the view as it is.May be this description might sound a little bit confusing,but in one word I want my scroll view during scrolling,to stop at any object in the view,just as in the case of a table view,so that it is user-friendly.
I have set the frame and content off set to the scroll view in view Will Appear method as follows:
-(void)viewWillAppear:(BOOL)animated
{
scrollView.frame = CGRectMake(0, 0, 320, 460);
[scrollView setContentSize:(CGSizeMake(320, 815))];
}
Note : I have a tab bar controller on the bottom of view,to navigate between controllers.
I have just gone through the UIScrollView as well as delegate class references.I have come across paging,scroll view will begin dragging,scroll to row at index path etc.. methods.Out of these what method I need to implement and what is the logic I need to write.
Want some valuable suggestions.
Thanks all in advance :)
OOps....its my mistake :(
We need to disable paging enabled property or set to no if it is set to true or yes either in IB or in our code snippet....thanks :)

Scroll view should not scroll when user interacts with slider in ios

I have a scroll view which has paging enabled.Its horizontal scrolling so when user scrolled from first page it would land the user in second page and second page has one slider.when the user slides(not touches) on this slider it automatically scrolls to first page because its horizontal scrolling too.Unless its touch on slider user end up in going to first page though user not intended to go to first page.
I had the same kind of problem once but with another control.
Take a look ate this answer to see if it canhelp you :
iPhone - UIScrollView and UIDatePicker scrolling conflict : the one interfer with the second
Does the second view on the scrollView contains any other container like WebView or imageView etc.
If you are showing your data directly on the ScrollView (i.e on second page).I recommend that to add a one more view on your scrollView on second view and render your data on that view the you wil be able to use the main ScrollView and the second view scroll separately.
You could try adding actions for UIControlEventTouchDown, UIControlEventTouchUpInside and UIControlEventTouchUpOutside to your slider. On touch down, do myScrollView.scrollEnabled = NO; and restore scrolling on touch up.

UIScrollView always bounce upwards and does not show scroll bar in iphone

This is probably simple but I do not seem to get it to work. I have a view and inside it I have a scroll view and inside it I have a view with some labels and a button. the height of the text inside the labels changes according to some condition so I need to scroll down to see it. But whenever I try to scroll down it bounce back up without giving me a chance to view the rest of the view.
Basically, I want when I scroll down, the view to remain down as it normally should. Besides I do not see the scroll bar at all when I'm scrolling.
I know I probably do not understand how scroll views work, so I'd appreciate any help to explain to me the behavior of scroll views.
P.S. I built my whole view in a nib file and this specific setup That I mentioned at the beginning is based on a suggestion from one question I read here.
Thanks, Mohsen
you need to set content size of your scroll view
[scrollView setContentSize:CGSizeMake(360,1000)];
you can make the content size dynamic as per your calculation.