my application needs help sceen on top of the home view controller.I have taken the tabbar controller as a root view controller and added navigation view controller .So in appearance of the first screen both tabbar and navigation bar appears along with view body.When i tried to place the help screens by pageviewcontroller examples at the time of view did load in the first screen tab view and navigation bar are coming front keeping the page view controller back .i have tried
[self addChildViewController:walkthrough];
[self.view addSubview:walkthrough.view];
[self.tabBarController.view bringSubviewToFront:walkthrough.view];
please help how to get the page view screen front.And is there any examples tutorial please help me
Note:Botn navigation bar and tabbar should not be hide
This is what I have done for walkthrough in my application. You can download this FXBlurView library from here:
https://github.com/nicklockwood/FXBlurView
In my .h file
#import "FXBlurView.h"
IBOutlet UIView *viewWalkThrough;
FXBlurView *overlayView;
In my .m file
#define SYSTEM_SCREEN_SIZE [[UIScreen mainScreen] bounds].size
#define kProfileWalkthrough #"ProfileWalkthrough"
if (![[[NSUserDefaults standardUserDefaults] valueForKey:kProfileWalkthrough] boolValue]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kProfileWalkthrough];
[[NSUserDefaults standardUserDefaults] synchronize];
overlayView = [[FXBlurView alloc] initWithFrame:CGRectMake(0, 0, SYSTEM_SCREEN_SIZE.width, SYSTEM_SCREEN_SIZE.height)];
[overlayView setDynamic:YES];
[overlayView setBlurRadius:5.0f];
[overlayView setBlurEnabled:YES];
[overlayView setTintColor:[UIColor blackColor]];
[self.view.window addSubview:overlayView];
[self displayOverlay:viewWalkThrough aboveView:self.view.window];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(closeWalkThrough:)];
[viewWalkThrough addGestureRecognizer:tapGesture];
}
- (void)closeWalkThrough:(UITapGestureRecognizer *)tapRecognizer {
[overlayView removeFromSuperview];
[self.viewWalkThrough removeFromSuperview];
}
- (void)displayOverlay:(UIView *)subView aboveView:(UIView *)superView {
subView.translatesAutoresizingMaskIntoConstraints = NO;
[superView addSubview:subView];
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[subView]|" options:kNilOptions metrics:nil views:NSDictionaryOfVariableBindings(subView)]];
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[subView]|" options:kNilOptions metrics:nil views:NSDictionaryOfVariableBindings(subView)]];
[superView layoutSubviews];
}
Related
By "strange", I am noticing the following behavior:
background color set by the ChildViewController does not appear
despite adding a basic tap gesture recognizer to the ChildViewController, there is no tap recognition
adding a UIButton to the ChildViewController results in the UIButton shown, but there is no response when tapping on the UIButton part
In my ParentViewController, I present the ChildViewController very generically, like so:
UIViewController *viewController;
viewController = (ChildViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"ChildViewController"];
[self addChildViewController:viewController];
viewController.view.frame = self.view.bounds;
viewController.view.translatesAutoresizingMaskIntoConstraints = NO;
viewController.view.center = self.view.center;
[self.view addSubview:viewController.view];
[self.view bringSubviewToFront:viewController.view];
[viewController didMoveToParentViewController:self];
And here are some very basic things I do in ChildViewController's viewDidLoad:
self.view.backgroundColor = [UIColor yellowColor];
UIButton *tapButton = [UIButton buttonWithType:UIButtonTypeSystem];
[tapButton addTarget:self action:#selector(tappedOnTap) forControlEvents:UIControlEventTouchUpInside];
//button view customization code omitted for brevity
tapButton.userInteractionEnabled = YES;
tapButton.enabled = YES;
[self.view addSubview:tapButton];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tappedOnView)];
[self.view addGestureRecognizer:tapGesture];
[self.view setUserInteractionEnabled:YES];
[self.view addGestureRecognizer:tapGesture];
I ensured that everything is hooked up correctly - however, there is no acknowledgment in tappedOnView and tappedOnTap when I tap on it, in both simulator or device.
Am I missing something basic about presenting a ChildViewController?
Edit
For those curious, this very basic app is on Github.
The containment calls are fine. But if you use the view debugger (), you'll see the frame is not correct. This is because you've turned off translatesAutoresizingMaskIntoConstraints, but you don't have any constraints. You can either turn that back on (and set autoresizingMask accordingly):
viewController.view.translatesAutoresizingMaskIntoConstraints = true;
Or you can define constraints rather than setting the frame (and redundantly setting the center):
//viewController.view.frame = self.view.bounds;
viewController.view.translatesAutoresizingMaskIntoConstraints = false;
//viewController.view.center = self.view.center;
[self.view addSubview:viewController.view];
[NSLayoutConstraint activateConstraints:#[
[viewController.view.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[viewController.view.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
[viewController.view.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[viewController.view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor]
]];
Try this:
ChildViewController *viewController;
viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"ChildViewController"];
viewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleheight;
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
Usually you don't need to do anything when adding a ViewController to another except those basic methods. since the views will be adjusted automatically and you don't need to set all those properties like size and center etc...
I want to know if it is possible to load/present modally a UIViewController with a "free form" size like the image below
I want to load the red one allways on top (allways visible) and interact with the ViewController below (blue one) at the same time.
EDIT: what i want is to show and hide FROM APP DELEGATE a small view controller to controll the music in my app.
I was trying with a xib file with a custom UIViewController as the file owner (see image below). The xib is being showed right the way i want, but the UIViewController associated to it, id doesn't load and i don't know why...
So i thought to do it with a UIViewController free formed but im not making it and i don't know wich is the best way
EDIT2:
With the xib file way i did the next:
In AppDelegate i have a function showPlayer that is called with local notification to show the xib
-(void)showPlayer:(int)tag andObjetoCancion:(NSArray *)objetoCancion
{
ZocaloPlayerViewController *vc = [[ZocaloPlayerViewController alloc] initWithNibName:#"ZocaloPlayerView" bundle:nil];
[vc setObjectoCancion:[objetoCancion mutableCopy]];
if (globals.isPlaying) {
[vc setCambiar:YES];
}else{
[vc setCambiar:NO];
}
//here playerView is a UIView initiated in didFinishLaunchingWithOptions
if (playerView == nil) {
playerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.window.frame.size.height, self.window.frame.size.width, altoPlayer)];
}
//keyWindow is UIWindow
//NSLog(#"Abro view %ld", (long)viewPlayer.tag);
keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:playerView];
[keyWindow bringSubviewToFront:playerView];
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"ZocaloPlayerView" owner:vc options:nil];
mainView = [subviewArray objectAtIndex:0];
mainView.translatesAutoresizingMaskIntoConstraints = NO; //This part hung me up
[playerView addSubview:mainView];
//needed to make smaller for iPhone 4 dev here, so >=200 instead of 748
[playerView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:#"V:|-0-[mainView]-0-|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:NSDictionaryOfVariableBindings(mainView)]];
[playerView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:#"H:|-0-[mainView]-0-|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:NSDictionaryOfVariableBindings(mainView)]];
[UIView animateWithDuration:0.3 animations:^{
playerView.center = CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height - mitadAltoPlayer);
[self.window layoutIfNeeded];
}];
}
ZocaloPlayerViewController *vc is being instantiated but the viewDidLoad function inside it is not being called.... That is my first problem...
With the UIViewController free formed way i don't know how to do it...
Ok, i solved my problem with this post Loaded nib but the view outlet was not set - new to InterfaceBuilder
(i was missing the UIView outlet)
and i changed my code in the showPlayer function to this:
-(void)mostrarPlayer:(int)tag andObjetoCancion:(NSArray *)objetoCancion
{
ZocaloPlayerViewController *vc = [[ZocaloPlayerViewController alloc] initWithNibName:#"ZocaloPlayerView" bundle:nil];
[vc setObjectoCancion:[objetoCancion mutableCopy]];
if (globals.isPlaying) {
[vc setCambiar:YES];
}else{
[vc setCambiar:NO];
}
if (playerView == nil) {
playerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.window.frame.size.height, self.window.frame.size.width, altoPlayer)];
}
//NSLog(#"Abro view %ld", (long)viewPlayer.tag);
keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:playerView];
[keyWindow bringSubviewToFront:playerView];
[playerView addSubview:vc.view];
[UIView animateWithDuration:0.3 animations:^{
playerView.center = CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height - mitadAltoPlayer);
[self.window layoutIfNeeded];
}];
}
self.refreshControl = [[UIRefreshControl alloc]init];
[self.objDiscussiontopic addSubview:self.refreshControl];
[self.refreshControl addTarget:self action:#selector(refreshTable) forControlEvents:UIControlEventValueChanged];
- (void)refreshTable {
//TODO: refresh your data
[self.refreshControl endRefreshing];
}
This is the code i am using to add refresh controller in my scroll view.
But when i pull down the scroll view the refresh control is not showing and the targeted method is also not called why ?
I am searching this for a while but didn't get any proper answer .
One more thing scrollview having VFL Constraint some thing like this :
//Pin scrolview to Parent View
[VFLConstraint allignSubViewViewHorizentallyWithSubView:self.objDiscussiontopic OverSuperView:[self view]];
[VFLConstraint allignSubViewViewVerticallyWithSubView:self.objDiscussiontopic OverSuperView:[self view] WithTopPading:[CommonFunction convertIphone6ToIphone5:0] AndBotomPading:[CommonFunction convertIphone6ToIphone5:57]];
+ (void)allignSubViewViewHorizentallyWithSubView:(UIView *)subView OverSuperView:(UIView *)superView{
NSDictionary *viewDict= NSDictionaryOfVariableBindings(subView);
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[subView]|" options:0 metrics: 0 views:viewDict]];
}
+ (void)allignSubViewViewVerticallyWithSubView:(UIView *)subView OverSuperView:(UIView *)superView WithTopPading:(float)topPading AndBotomPading:(float)bottomPading{
NSDictionary *viewDict= NSDictionaryOfVariableBindings(subView);
NSDictionary *metrics=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:topPading],#"topPading",[NSNumber numberWithFloat:bottomPading],#"bottomPading", nil];
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-topPading-[subView]-bottomPading-|" options:0 metrics: metrics views:viewDict]];
}
Try to:
[self.scrollView insertSubview:self.refreshControl atIndex:0];
Check the contentSize it can be less that frame size, if so use this line of code:
self.scrollView.alwaysBounceVertical = true
I don't think a UIRefreshControl is designed to work with plain scroll views. Apple's docs specifically refer to UITableViews when talking about refresh control.
You can look at third party pull to refresh libraries to add this to UIScrollView
I am fairly new to iOS. I tried to look this up but couldn't find a definite answer to the following.
I have a SWRevealViewController to handle side menu bar from my FirstPage.
When the SWReveal appears after clicking btn_Menu (or by swiping left) I want the FirstPage to become grey and unusable.
I see that in FirstPage we have to do the following:
[btn_Menu addTarget:self.revealViewController action:#selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
I need to change the revealToggle method somehow, or write a new selector in FirstPage which darkens it first, and then calls revealToggle ? I am unsure what's the best and easiest way to get this done. Thanks a lot.
In your FirstPage viewDidLoad do this code.
- (void)viewDidLoad
{
SWRevealViewController * revealController=[[SWRevealViewController alloc]init];
revealController = [self revealViewController];
[self.view addGestureRecognizer:revealController.panGestureRecognizer];
revealController.delegate=self;
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
[btnSideMenu addTarget:revealController action:#selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
}
After that add this delegate method of SWRevealViewController in to your FirstPage.
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
{
if (revealController.frontViewPosition == FrontViewPositionRight)
{
UIView *lockingView = [UIView new];
lockingView.translatesAutoresizingMaskIntoConstraints = NO;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:revealController action:#selector(revealToggle:)];
[lockingView addGestureRecognizer:tap];
[lockingView addGestureRecognizer:revealController.panGestureRecognizer];
[lockingView setTag:1000];
[revealController.frontViewController.view addSubview:lockingView];
lockingView.backgroundColor=[UIColor grayColor];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(lockingView);
[revealController.frontViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:#"|[lockingView]|"
options:0
metrics:nil
views:viewsDictionary]];
[revealController.frontViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[lockingView]|"
options:0
metrics:nil
views:viewsDictionary]];
[lockingView sizeToFit];
}
else
[[revealController.frontViewController.view viewWithTag:1000] removeFromSuperview];
}
I have a search bar on top of a table view set up using auto layout like so:
_searchBar.translatesAutoresizingMaskIntoConstraints = NO;
_tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|[_searchBar]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_searchBar)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|[_tableView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[_searchBar][_tableView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_searchBar, _tableView)]];
Everything looks nice when I run it. But when I do _searchBar.showsScopeBar = YES; before I start editing the search bar, the search bar and table view do not resize automatically. Even when I do [_searchBar sizeToFit], the table view does not resize and move down. Why??
Note: I'm not putting the search bar as the table view's header; it's just a parent view and two subviews.
Note 2: I checked the intrinsicContentSize of _searchBar before and after I call _searchBar.showsScopeBar = YES; and the size does indeed change.
You have to invalidateIntrinsicContentSize:
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
searchBar.showsScopeBar = YES;
[searchBar invalidateIntrinsicContentSize];
[searchBar setShowsCancelButton:YES animated:YES];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
searchBar.showsScopeBar = NO;
[searchBar invalidateIntrinsicContentSize];
[searchBar setShowsCancelButton:NO animated:YES];
}
See UISearchBar's scope button won't show up iOS6