I've been following this example in everything to create a UIWindow on top of the statusBar.
My UIWindow gets displayed on top of the statusBar and all is fine, but the actual view of the app (the one with the button) doesn't respond to my actions:
I'm using Storyboards and iOS6.
Here's my code for creating a statusBar overlay:
- (void)viewDidAppear:(BOOL)animated {
UIWindow *overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
AppDelegate *app = [[UIApplication sharedApplication] delegate];
overlayWindow.rootViewController = app.window.rootViewController;
app.window = overlayWindow;
[overlayWindow makeKeyAndVisible];
}
The view under the statusBar does not respond and I can't tap on the UIButton. Is it possible to somehow make the UIWindow with the interface of my app accept the touches ignoring the ACStatusBarOverlayWindow? How can that be done?
Usually if a button does not respond to a touch it's because the button is outside of the bounds of it's parent's UIView.
Your code does not seem to be the appropriate approach to the problem you're trying to solve. If you just need your window to have a status bar, or you just need to add a button to you current view, the way you're doing it is probably incorrect.
Personally I've never seen anyone instantiate a UIWindow in a viewDidAppear, since the app comes with it's own UIWindow. You should be using a UIView and adding your overlay to it.
As a side note if you were to do it the way you're attempting to, then your window would at least need a frame. So initWithFrame:CGRectZero would be initWithFrame:CGRectMake(0,0,320,480) or something along those lines.
A better way to approach the problem is to instantiate a UIViewController and set it as your rootViewController. Or simply add your button to the current viewController's view.
- (void)viewDidLoad {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(myMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Tap Me" forState:UIControlStateNormal];
[button sizeToFit];
[self.view addSubview:button];
}
Related
I have a UIViewController which I want to display a UIView that renders as a menu. This menu will have several buttons on it. I wanted to reuse this menu a few different places in my app so I figured I would create a class called ViewFactory that has a method that returns a UIView with these buttons.
On my ViewController I call this method and get the returned UIView and add it as a subview.
This works just fine. I can see the view and all its buttons, however, the buttons do not respond to any touch events. Not sure why this is the case and curious to know what I am doing wrong.
Here is my code for the ViewFactoryClass:
- (UIView *) addCloseRow
{
// UIView container for everything else.
UIView *navRow = [[UIView alloc] initWithFrame:CGRectMake(0,225,350,45)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.userInteractionEnabled = YES;
[navRow addSubview:button];
[button addTarget:self action:#selector(closeButtonTouchDownEvent) forControlEvents: UIControlEventTouchDown];
navRow.userInteractionEnabled = YES;
return navRow;
}
In my main NavigationController class here is how I am calling and getting the UIView:
ViewFactory *factory = [[ViewFactory alloc] init];
[self.navigationController.navigationBar addSubview:[factory MainNavigationUIView]];
Again, the UIView shows up but the buttons never respond to anything.
You added the button with target and selector for ViewFactoryClass
And now you are creating instance and trying to call an action from ViewFactory class.
You can change the method to something like this:
- (UIView *) addCloseRow : (id)object {
...
[button addTarget:[object class] action:#selector(closeButtonTouchDownEvent) forControlEvents: UIControlEventTouchDown];
...
}
I have created a utility app that links by button to another xib called scene - I am trying to create a navigation control for that link. When the button is clicked to then have a 'back' button on my scene xib. I don't wish to have a navigation bar visible on the Main View Controller or the Flipside View Controller. I'm quite new to iOS and I have no idea how to do this?
Would it maybe just be better to have a button going back to menu on a custom HUD? I don't know if that can be done?
Thank you for any help in advance, and thank you for your time
you could create a custom UINavigationBar on your scene xib, and add the custom back button to it if you don't want to create NavigationController , alternate would be that you could just make your first view as NavigationController and push the Scene view over it and it will brings the back button on the child view which is scene, keep your navigationBar hidden when you are on MainViewController and show only on scene view.
For hide UINavigationBar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
And Your can crate Custom UIButton and put anywhere (As Your requirement).
and in its method, Write code for go back to UIViewController (previous UIVieController).
Such like,
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[btnBack addTarget:self action:#selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
btnBack.frame = CGRectMake(10, 10.5, 36, 39); // change it , As your wish
[btnBack setBackgroundImage:[UIImage imageNamed:#"MMBack.png"] forState:UIControlStateNormal];
[self.view addSubview:btnBack];
// call method of UIButton
-(void)goBack:(UIButton *) Sender
{
[self.navigationController popViewControllerAnimated:YES];
}
I need to add a subview to left part of UIViewController, which shows the user that there is something near the left part of screen, when masterview is hidden(in portrait orientation). And this view must move with left part of UISplitView. Something like the view with arrow in these two images. (Sorry for the russian interface)
http://s2.uploads.ru/8EHJI.png
http://s2.uploads.ru/NhEam.png
But my problem is that when I try to add such a view, it clips to bounds of masterview and is not visible when masterview is hidden. I think, I'm doing it wrong and there is an easy way to do this.
Update: I've tried to make some hack like:
-(void) clipToBoundsRecursive:(UIView *)someView
{
NSLog(#"%#", someView);
someView.clipsToBounds = NO;
for (UIView *v in someView.subviews)
{
[self clipToBoundsRecursive:v];
}
}
and send it to view of splitviewcontroller.
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
[self clipToBoundsRecursive:splitViewController.view];
It takes effect at first time (subviews outside the masterview's bounds shows, but after first show/hide animation they disappears and don't appear even if I call this method again)
You can add the view directly to the window's view, though you will have to manually manage its position depending on when the device rotates. Views added to the window.view will appear above the rootViewController.view.
I have described here a simple Logic for you: (how to add a UIView in Window and call it from your master or detail view )
Create UIView in #import "AppDelegate.h" ,
- (void) CreateViewInWindow
{
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 780)];// set as u wish
myView.backgroundColor = [UIColor redColor];
// I have added myView to the Window with a specific animation , your can give animation as you like. :)
[UIView transitionWithView:self.window duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve // change to whatever animation you like
animations:^ { [self.window addSubview:myView]; }
completion:nil];
}
Here create a simple UIButton in the DetailViewController.m file (You can put the code in either of the files, DetailViewController.m OR MasterViewController.m)
UIButton *btnShowView = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnShowView addTarget:self action:#selector(btnShowViewTapped:) forControlEvents:UIControlEventTouchUpInside];
btnShowView.frame = CGRectMake(20, 30, 174, 35);
//[btnLoginInner setBackgroundImage:[UIImage imageNamed:#"LoginBut.png"] forState:UIControlStateNormal];
[self.view addSubview:btnShowView];
In button tapped method, write code for calling UIView from AppDelegate, and also don't forget to add #import "AppDelegate.h" in DetailViewController.m,
-(void)btnShowViewTapped:(UIButton *) Sender
{
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[del performSelector:#selector(CreateViewInWindow) withObject:nil afterDelay:0];
}
Above code is a simple logic for your problem, It might be helpful for you.
Sounds to me like your app could benefit from PKRevealController.
Try with deselecting auto layout option in identity and type pan if you are using nib otherwise set autoresizing mask to view that currently clipping. I believe it will solve the issue
I am fairly new to iOS development. My requirement is I am designing an app that contains 5 screens . I have a set of UI controls( 1 UIImageView 5 UIButtons acting like tab bars for each screen) that are common for all the screens. When a button is clicked only the bottom half of the view needs to change with a relevant details while the buttons stay intact(similar to tab control in windows).
Is there a way to achieve this design? Can I share UI controls across multiple screens without repetition in code or
Is there a way to change only the bottom half of the screen when a button is clicked?
You could have a separate class that would create your UIControls and then for each viewcontroller you call the appropiate method to get the UIControls you want.
#interface UIControlMaker : NSObject{
id controlmakerDelegate; // This is so that you can send messages to the viewcontrollers
}
#property (nonatomic,retain) id controlmakerDelegate; // Release it in dealloc method
- (id)initWithDelegate:(id)delegate;
- (UIView *)createCommonUIControls;
In the implementation file
#implementation UIControlMaker
#synthesize controlmakerDelegate;
- (id)initWithDelegate:(id)delegate{
if(self = [super init]){
[self setControlMakerDelegate:delegate];
return self;
}else
return nil;
}
- (UIView *)createCommonUIControls{
UIView *uicontrolsHolder = [[UIView alloc] initWithFrame:CGRectMake(2,40,320,50)];
// Create as many uicontrols as you want. It'd be better if you have a separate class to create them
// Let's create a button for the menuItem
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0 , 0, 50, 35)];
button.backgroundColor = [UIColor clearColor];
[button setTitle:#"Button 1" forState:UIControlStateNormal];
[button addTarget:controlmakerDelegate action:#selector(buttonOnClick) forControlEvents:UIControlEventTouchUpInside];
[uicontrolsHolder addView:button];
[button release];
// Add more uicontrols here
retun [uicontrolsHolder autorelease];
}
Then in your viewcontrollers create an instance of UIControlMaker and call the createCommonUIControls method which will return a View that you can add to your viewcontroller. Hope that was clear.
Essentially i want to display a notification just beneath the UINavigationController, covering the area that would be occupied by the top most UIViewController's view. However i want the background image to extend upwards and partly cover the UINavigationBar
The finished product should hopefully look like the below
The trick comes in that i only want this to apply to certain views with the view Hierarchy, so attacking the problem by using [UIApplication keyWindow] might not be the best idea. Also i assume that by using views outside of the private UINavigationTransitionView won't be part of the view transition animation, leaving my view on top of the controller beneath when this one is popped.
The view of the topmost view controller doesn't help either, as it's frame is terminates at the base of UINavigationBar, meaning arrow won't overlap the UINavigationBar
Suggestions?
Thanks
Since it seems that you are facing the problem with Navigation Bar only as that will not allow to overlap the View.
This is tricky part....
Just use the Custom back button set the image over it in left of the Navigation bar Button
UINavigationBar *bar = [self.navigationController navigationBar];
UIButton *btn;
btn = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 100, 48)];
[btn setImage:[UIImage imageNamed:#"left.png"] forState:UIControlStateNormal];
btn.backgroundColor = [UIColor clearColor];
[bar addSubview:btn];
[btn release];
This is surely going to help you & solve all your Queries for the same ....