I am using a segmented control as my navigation. One of the buttons in my segmented control is a "share" button; when clicked, want to display an actionsheet from the segmented control, with the arrow pointing up, towards the segmented control bar.
This is not placing the actionsheet popover correctly. Actionsheet Arrow not facing up, it's facing down.
Thanks for helping!
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
[self.actionSheet showFromRect:CGRectMake(190,220,screenWidth,screenHeight) inView:self.view animated:YES];
A UIActionSheet presented on the iPad is presented in the middle of the screen and with no arrow. You question is unclear.
I believe you are (or should) actually using a UIPopoverController for that purpose.
Can you complete your code example?
The solution, albeit hacky, for this issue was derived from messing with the parameters in
-(void)showFromRect:(CGRect)rect inView (UIView *)view animated:(BOOL)animated
and by the following SO post:
UIActionSheet Change arrow position?
Related
For an iphone project with an "unique" design (with which i am not happy at all) I need to draw a custom view which partially overlaps the navigation bar of a controller in a UINavigationController. Target is iphone/ios 6 with a fixed device orientation (portrait).
My currents solution is to disable the navigation bar programatically via self.navigationController.navigationBar.hidden = YES; in viewDidLoad of my controller and to draw a "fake" navigation bar and paint over this.
This leads to the problem that the status bar color remains black (since there is no real navigation bar visible).
Ios 6 status bar color is discussed here: Status bar color in iOS 6?
I already tried to use [self.view insertSubview:OVERLAPVIEW aboveSubView:self.navigationController.navigationBar] but it did not work and OVERLAPVIEW was drawn beneath the navigation bar.
Is there another way to overlap the navigation bar with another view (z-wise)?
Or is there a way to change the status bar color when no navigation bar is shown (unfortunately in addition to this the view with the overlap is the main view of the app and the first screen visible to the user)
Full disclosure: I am an ios noob and stack overflow lurker - this is my first question on stack overflow, please help me to clarify my question and improve my stack overflow skills if necessary.
Use
[self.navigationController.view addSubview:OVERLAPVIEW];
instead of
[self.view insertSubview:OVERLAPVIEW aboveSubView:self.navigationController.navigationBar];
You can adjust the frame of your view according to make navigation bar partially visible.
I solved this issue by hiding the Navigation bar with
self.navigationController.navigationBar.hidden = YES;
and by adding a navigation bar to my view. Everything added after this new navigation bar will to overlap it (you could use index [parentView.subviews objectAtIndex:0]; as well).
The color of the status bar changes as needed.
In the case of the splash screen i do exactly the same and overlap the navigation bar with the fullscreen splash image.
-(void)viewDidLoad{
[super viewDidLoad];
UINavigationBar * navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 49)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"SPLASH"];
[navigationBar pushNavigationItem:item animated:NO];
[self.view addSubview:navigationBar];
CGRect frame = [[UIScreen mainScreen] bounds];
frame.origin.y -= 20;
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:frame];
splashImage.image = [UIImage imageNamed:#"splash"];
[self.view addSubview:splashImage];
}
It seems that this answer solves my issue
Add UIView Above All Other Views, Including StatusBar
Note: at the moment i am not going down this road and I will accept this answer once I tried it (I postponed solving this problem at the moment and it might take a while)
my UIPopOverController loses its content sometimes, when being rotated (not reproducable) or if for example I open some content from a tableview in landscape, rotate the device to portrait and then open the same content in portrait.
The Popovercontroller is displayed but no content is visible i.e. it is black.... has anyone stumbled upon this or anything similar?
I encountered similar problems when using UIPopoverController after rotation occurred (UIPopoverController's size changed strangely, it repositioned itself to strange places in screen etc).
The trick that worked for me was to overload the UIViewController's didRotateFromOrientation:(UIInterfaceOrientation) method in the app. So overload the method from your app's UIViewController class that is being displayed when UIPopoverController is displayed and call UIPopoverController's presentPopoverFromRect: method again from there:
-(void) didRotateFromOrientation:(UIInterfaceOrientation)uiOrientation {
if (popoverController.popoverVisible) {
// Define rect to be the UI component's rect where you want to tie the popoverController
CGRect rect = CGRectMake(...);
// This method will reposition the popover correctly
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
}
}
Note that if you are tying UIPopoverController to UIBarButtonItem using UIPopoverController's presentPopoverFromBarButtonItem: method, the system should then automatically take care of positioning the popover correctly after the rotation.
Does anyone know if the uinvagitionbar of a uinavigationcontroller can be moved down? I'd like to move it around 200 pixels down to have a logo on top. From my research, I understand that the navigationbar should not be subclassed and there are only two properties that should be changed, it's color and it's visibility. So is this impossible?
I tried moving it's frame, but to no avail.
I've seen other apps do it, but I'm thinking it might be a toolbar? Can the toolbar be repositioned?
Thanks
Just change the size of the frame of the navigations controller's view.
CGRect frame = navigationController.view.frame;
frame.size.height -= 200.0f;
frame.origin.y += 200.0f;
navigationController.view.frame = frame;
You can then add whatever view you'd like to the view or window that contains the navigationController's view.
There a few tricky things to consider if you plan on doing this by presenting a modal view controller, however.
You can hide the self.navigationController and put another navigation bar in the code which will move according to your frame set.
Yes the tool bar can be repositioned. Just take a control in your code and set its frame as per your requirement.
Happy Coding...
I am experiencing some weird behavior with my iPad app. I usually add a view to my viewController like this:
CGRect bounds = [[UIScreen mainScreen] applicationFrame];
// Add Basic View
UIView *myView = [[UIView alloc] initWithFrame:bounds];
myView.backgroundColor = [UIColor blackColor];
self.view = myView;
[myView release];
On the iPhone this always works like a charm. On my iPad app however, I add a toolbar to this self.view as a subview with the rectangle (0, 0, self.view.frame.width, 100). Sometimes this works out well and the toolbar displays right below the status bar, yet in certain conditions (eg. when the iPad is lying flat on a table and the interface orientation is portrait) my toolbar slides partly below the status bar. Yet as soon as I rotate the device everything is fine again and the toolbar is aligned properly with the status bar.
I have tried some workarounds with adding values a few points to the origin.y property of the toolbar, yet when I do this the toolbar gets an offset to the status bar after rotating the device. I am really confused by this, did anybody else ever experience this problem? If so, how did you fix it?
Thanks a lot!
I have an application where a UIToolBar is to be constantly on the bottom side of the screen. No matter the device orientation.
The toolbar must have the same screen width and always be justified to the bottom side.
If the device rotates, the toolbar has to assume the new width and continue to be justified on the bottom.
Is there a way to do that programmatically?
thanks for any help.
First off, auto-rotation can be a little tricky. For example, if you are using a UITabBarController, you will need to subclass it and add the appropriate delegate methods. You should read up on auto-rotation via the Apple docs and Google, before really diving in.
To answer your question specifically though, here is how you would need to declare the UIToolbar such that it will auto-rotate when you have the app set up to do so:
// I keep this definition in a file called constants.h since I use it a lot
#define SCREEN_FRAME [[UIScreen mainScreen] applicationFrame]
UIToolbar *tb = [[[UIToolbar alloc]init]autorelease];
// this frame will position a toolbar at the bottom of the screen
tb.frame = CGRectMake(0,
SCREEN_FRAME.size.height-tb.frame.size.height,
SCREEN_FRAME.size.width,
tb.frame.size.height);
//Setting the auto-resizing mask will make the toolbar resize when the viewController
//it resides in rotates.
tb.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Yes. Have a look at autoresizing masks.
Use a navigation controller, and make use of the toolbarItems property.