UIScrollView doen't scroll when is into a UIPageViewController - ios

I'm trying to use a UIScrollView as the content view into a PageViewController, I've configured the Page controller as it is on the sample project of xcode.
The problem is that the content has a Scroll view but it just doesn't scroll at all, I have seted the Content size and the properties for the scroll view.. I guess it is right configured.
- (UIScrollView *)scrollView
{
if (_scrollView == NULL) {
_scrollView = [[UIScrollView alloc] init];
_scrollView.backgroundColor = [UIColor whiteColor];
_scrollView.scrollEnabled = TRUE;
_scrollView.alwaysBounceVertical = TRUE;
}
return _scrollView;
}
Then, I'd attached the gestures of my view to be the UIPageViewController gestures array, this was preventing a navigation bar to perform well, so I made a validation on:
gestureRecognizerShouldBegin:
And it is ok now.
I don't know how to fix this issue :S

try this
[scrollmngmt setScrollEnabled:YES];
[scrollmngmt setContentSize:CGSizeMake(320, 1200)];
[self setScrollmngmt:nil];

Related

Subviews not appearing when UIScrollView is enabled

In my app, there is a subview that I use to implement auto-complete. It appears when a button is clicked. It works fine in normal case. But when I embed the whole lot into a UIScrollView, it doesn't work. Here is my code
_scrollArea=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1000)];
_scrollArea.contentSize=CGSizeMake(320, 1000);
_scrollArea.scrollEnabled=YES;
_scrollArea.userInteractionEnabled=YES;
[self.view addSubview:_scrollArea];
_viewForAuto.hidden=false;
now here is the action call for the button click
- (IBAction)buttonOnFromPlace:(id)sender {
_selectedSlot=1;
_viewForAuto.hidden=false;
[self.view bringSubviewToFront:_viewForAuto];
[_autoFillData removeAllObjects];
[_theTable reloadData];}
UPDATE: The scroll itself is not working
UPDATE 2: Updated Code(got the sub view to the front, cant get the scroll to work)
_scrollArea.contentSize=CGSizeMake(320, 700);
_scrollArea.scrollEnabled=YES;
the action call
- (IBAction)buttonOnFromPlace:(id)sender {
_selectedSlot=1;
_viewForAuto.hidden=false;
[_scrollArea bringSubviewToFront:_viewForAuto];
[_autoFillData removeAllObjects];
[_theTable reloadData];}
If we want a scrolling for UIScrolllView,Our contentSize is must be greater then the frame size.If you want scrolling for you scroll view try this
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,2*_scrollArea.frame.size.height);

iOS 7 UIViewController (with navigation bar) doesn't inset UIScrollView

I've got a UINavigationController with a UIViewController showing a navigation bar.
I've specifically set [self setAutomaticallyAdjustsScrollViewInsets:YES];, though this should be YES by default anyway.
I add a UIScrollView:
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.scrollView];
However, the UIScrollView's contentInset is {0, 0, 0, 0}, so I am wondering why it doesn't inherit the content inset from the view controller as the documentation states it would.
If I add subviews to the scroll view and set their Y to be self.scrollView.contentInset.top they don't appear below the navigation bar, which is what I am expected.
What am I doing wrong here? It works fine if you start out with a UITableViewController since it correctly inherits the contentInset from the view controller.
Thanks!
self.view = self.scrollView;
Works fine for me.
Tested with UIWebview:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view = self.webView;
}
It adjusts the scroll view bounds, not the content insets.

UIScrollView does not scroll anymore after the view re-appear

I have a scrollview on the main view after the display of another view the scroll stop scrolling.
On view appear I tried to refresh the scroll but no luck
calling this:
-(void)refreshScrollView{
NSLog(#"scroll Content Height %f",answerScolledHeight );
NSLog(#"scroll View Height %f", scrollView1.frame.size.height );
[scrollView1 setScrollEnabled:YES];
[scrollView1 setContentSize:CGSizeMake(320, answerScolledHeight)];
[scrollView1 setContentOffset:CGPointMake(0, 0)];
}
It reads the right values without working:
2013-03-21 17:56:01.434 ----[38464:14003] scroll Content Height 256.000000
2013-03-21 17:56:01.434 ----[38464:14003] scroll View Height 194.000000
The problem comes after the display of the settings view:
SettingsController* controller1 = (SettingsController *)[self getSettingsViewController];
[self presentModalViewController:controller1 animated:YES];
And when the settings is closed the scroll does not work anymore
- (IBAction)doClose:(UIBarButtonItem *)sender {
[self dismissModalViewControllerAnimated:YES];
}
The viewDidAppear, I try to run some commands the first time to limitate the problems as I am using ECslidingViewController (a wipe menu)
- (void)viewDidAppear:(BOOL)animated{
if (!isActive){
answerUpY = self.answerView.frame.origin.y;
answerDownY = self.questionBackground.frame.origin.y +self.questionBackground.frame.size.height - self.answerToggle.frame.size.height - PADDING_1;
isActive = TRUE;
[self slidingControllerAppear];
}else{
[self refreshScrollView];
}
}

UITableView: Painting-Behavior of Header- and Footer-View

Why does the header and footer of a tableview always stays on top of the view hierarchy, but not the cells of the table?
Here is what I got:
A table view with custom cells, a footer and a header
A Navigationbar with a menu-Button on the right
When the user taps the menu-button, a semi-transparent menu (UIView) fades in from the top, but not over the navigationbar, only over the view of my tableviewcontroller
When the user tabs a menu-button, the menu slides back to (0,-menuHeight)
But when the menu is over the header, this menu-region is behind my header
I anchored the menu on the view of my tableviewcontroller, beacause I want the navigationbar allways be visible. the solution to anchor it on the navigationbar solves the problem with the header-view, but covers the navigationbar.
Has anyone an idea how to solve this problem? Why are the cells painted correctly?
You should probably not interfere directly with the internal view hierarchy of UITableView. Apple is free to order a table view's subviews as they see fit (and change it in future releases).
Instead, place the table view and your menu view into a common container view and make the latter the main view of your view controller. That way, you can be certain that your menu view will always be above the table view.
I changed my design, but now I do not get touch-events in my table.
But when I add this method - I see, that I'm touching the tableviewcontroller...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(#"ShieldingViewController received touch");
[self.buttonMenu shieldingViewTouched];
}
Here is what I changed:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect viewFrame = self.view.frame;
viewFrame.origin.y = 0;
UIView *rootView = [[UIView alloc] initWithFrame:viewFrame];
rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// Setup the table view
UITableView *newTableView = [[UITableView alloc] initWithFrame:viewFrame style:self.tableView.style];
newTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
newTableView.backgroundColor = [UIColor darkGrayColor];
UIView *menuLayerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)];
self.tableView = newTableView;
[rootView addSubview:self.tableView];
[rootView addSubview: menuLayerView];
self.view = rootView;
[[CustomNavigationController instance] setCurrentViewForMenu: menuLayerView];
[[CustomNavigationController instance] showMenuInNavigationBarForController:self];
[newTableView release];
[menuLayerView release];
[rootView release];
}

How do I detect touches on UIStatusBar/iPhone

I'm trying to detect any touch on the iPhone's UIStatusBar but its not working. I've tried subclassing UIApplication and UIWindow to access it but still nothing.
Based on Tom's answer, I wrote the code. It works well.
- (void)viewDidLoad {
[super viewDidLoad];
// required
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(0.0f,1.0f);
[scrollView setContentOffset:CGPointMake(0.0f,1.0f) animated:NO];
// optional
scrollView.scrollsToTop = YES; // default is YES.
[self.view addSubview:scrollView];
}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
NSLog(#"Detect status bar is touched.");
/* Your own code. */
return NO;
}
You need to have a UIScrollView in your responder chain, and it needs to have a delegate set. You can then override scrollViewShouldScrollToTop: in the delegate, which will be called when the user taps on the status bar. Be sure to return NO if you don't want the default behavior of scrolling the scroll view back to the top.
You can't. The status bar is held by the application. You can only turn it on and off.
More importantly, any fiddling with the status bar is likely to get your app rejected by Apple because it could interfere with the operation of the hardware e.g. disguising or hiding a low battery.
If you need full screen touches for your views you should just hide the status bar.

Resources