I have a scrollView with its content view and finally a subview on the content view.
I would like to stop scrolling [scrollView scrollEnabled:NO] from the subview. Can I get at the method?
I don't have Xcode in front of me, but can't you get at the superview with self.superview from your subview code?
For instance, like so:
[subview.superview scrollEnabled:NO];
To stop scrolling [scrollView scrollEnabled:NO] from the subview? Maybe you need a viewController which control the views. Do you clear about the MVC?
Related
I am having more lines of contents which exceeds the ViewController height, I want to show it in same screen by scrolling. Is there any way to achieve that?
Use a UIScrollView and put your contents in it.
You can use UIScrollView or UITableView for the same.
Add all views as subviews of one super view say containerView. Add containerView as sub-view of UIScrollView. Do not forget set appropriate content size of UIScrollViiew. You can do it by proper autolayout or programatically as
CGRect contentRect = CGRectZero;
for (UIView *view in self.scrollView.subviews) {
contentRect = CGRectUnion(contentRect, view.frame);
}
self.scrollView.contentSize = contentRect.size;
You can also use UITableViewController with static cells. You can add view in static cells and you are good to go. UITableViewController itself manages scrolling.
Hope it helps. Happy Coding!!
You can use a UIScrollView (As #luckyShubhra and #chedabo suggested) , you can setup the UI correctly in Storyboard in this case and have the contentsize of the UIScrollView set to the size of the viewController contained in the UIScrollView...
Then also the UITableView (As #luckyShubhra suggested)... if your data is setup to deal with as a list of NSStrings or object, this can work well...
Then if the content is a NSString, and you would use a UILabel, I would suggest changing it to a UITextView... This will make it possible to scroll as well. If the contents is not to be edited just change the Selectable and Editable booleans to false...
UIScrollView or even UITextView can help that too. if it is HTML, you may consider of rendering it with UIWebView.
just make sure the control height is lesser than the view controller, then it will render the contents in a scrollable manner.
I have a UITableView, Each cell has a view like below image, a UIScrollView in background and another view on the UIScrollView.
UIScrollView contains multiple images and user should be able to see them by swiping right or left on the table cell, But as second View (red area) covered UIScrollview, Scrolling not work when I swipe my finger in this area, But in the top of red area it's ok and works perfect.
I see in the other application that have this feature that scrolling is possible in all cell height even when they have other views that covered the background.
I should be grateful if you share your suggestions with me :)
try disable userInteraction on the view in the red area, this will allow touches to pass though it. this can be done through the storyboard, or just go view.userInteractionEnabled = false
Keep this line of code in ViewDidLoad method:
[self.view setExclusiveTouch:YES];
And if this doesn't work add it for your tableview
[tableView setExclusiveTouch:YES];
Or else at the end you can add the swipe gesture to the tableview cell and call the selector and do which intended to be done.
Add Second view as a subview of firstView or ScrollView.
[scrollView addSubview:firstView];
[firstView addSubview:secondView];
For me the issue was that the view was not a subview of the UIScrollView. You can check this by setting a breakpoint somewhere in your UIScrollView or the parent view controller class and entering the following in your debugger window:
po myScrollView.subviews
Then check the output to make sure that your element is within the subviews.
scrollView.isScrollEnabled = false
and handle the scrolling by code.
func scrollToPage(page: Int) {
var frame = scrollView.frame
frame.origin.x = frame.size.width * CGFloat(page)
scrollView.scrollRectToVisible(frame, animated: true)
}
view.userInteractionEnabled = NO
Hi everyone. I dragged a UIScrollView to my storyboard, then I added a UIView on top of that UIScrollView. This UIView loads another subview dynamically depending on what the server throws to this app.
The problem is the UIScrollView is not scrolling the content, even though I made the loaded UIView bigger than the UIScrollView. I'm not invoking [myScroller addSubView:myUiView]. Am I doing it right? Thanks in advance!
For every time you change the content try calling
//removeFromSuperview the UIView was set as content view
self.myScroller.contentSize = self.myUiView.frame.size;
[myScroller addSubView:myUiView];
Don't forget to link both views on Interface Builder
PS: In this apporach the subView must not be inside the scrollView on IB
You must set the content size of the scroll view.
Add this in your view controller.
- (void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
myScroller.contentSize = CGSizeMake(CGRectGetMaxX(myUiView.frame), CGRectGetMaxY(myUiView.frame));
}
I have a uiview that i need to add a subview to, the subview's width
is twice the width of the parent view, and i don't want this suview to overflow,
i need the overflown area to be hided, how can i achieve that?
You can use this:
view.clipsToBounds = YES;
For your superview - the view which has the subview, call message
[*SUPERVIEW* setClipsToBounds:YES];
Dear all,
i have UIView and UIScrollView inside UIViewController.
UIView and UIScrollView has same width, width equal 500,
I need UIView to scroll when I scroll the UIScrollView. How can I achieve this?
P.S: UIView is not a subview of UIScrollView
Thank you for answers!
If i understand correctly u need to add into ur viewControler a horizontalscroll view and then into that view and into that u add ur view and another scrollview.
I hope i understand ur question correctly.
you need to make your UIView as the subview of UIScrollView then only you will be able to scroll the UIView when you scroll your scrollview.