It it possible let Navigationtroller not to display full screen? - iphone

I have an UIView (320*300 the view of an UIViewController), I hope to display UINaviationCotroller and control the navigation within this view size.
Is it possible?
Thanks
interdev

Below you'll find out a snippet of code that does it. But let me give you a word of wisdom. Don't do it. Avoid at all costs. Apple doesn't recommend doing that. You will have nightmares and will be busy patching edge cases. It worked well in 3.x, with iOS 4 you'll have to work around a lot of special cases.
- (void) _adjustViewControllerforTicker {
TickerView* vv = [ApplicationContext getTickerView];
if ([PreferenceDataModel isTickerOn]&& self.navigationController.view.frame.origin.y==0) {
CGRect tableRect = self.tableView.frame;
self.tableView.frame = CGRectMake(tableRect.origin.x,tableRect.origin.y, tableRect.size.width, tableRect.size.height -20);
UINavigationController *nav = self.navigationController;
CGRect gframe = CGRectOffset(self.navigationController.view.frame, 0, 20);
self.navigationController.view.frame = gframe;
if (!vv) {
vv = [[TickerView alloc] initWithFrame:CGRectMake(0, 0, 480, 20)];
[nav.view addSubview:vv];
[vv release];
self.tableView.contentInset=UIEdgeInsetsMake(0,0,20.0,0.0);
}
}
if (![PreferenceDataModel isTickerOn]) {
self.tableView.contentInset= UIEdgeInsetsZero;
if (vv){
[vv removeFromSuperview];
vv=nil;
}
}
}

yes.. why do you think it wouldn't be? It is probably non-standard but technically it can be done

Related

UISegmentedControl with Direction or Arrow theme

I have implemented UISegmentedControl with Direction theme using BASequenceControl from cocoacontrols.com.
I have added BASequenceControl.h and BASequenceControl.m classes and required images from GitHub
Great. Its working fine for me..However I have a concern with the last segment section tip.
Its displaying the junk space of last segment section.
Original Screen Shot
I need like this
The code I have Implemented
#import "BASequenceControl.h"
BASequenceControl *bASequenceControl = [[BASequenceControl alloc] init];
bASequenceControl.frame = CGRectMake(10, 10, 200, 44);
[bASequenceControl addSegmentWithTitle:#"First" animated:NO];
[bASequenceControl addSegmentWithTitle:#"Second" animated:NO];
bASequenceControl.leftMargin = -22;
bASequenceControl.rightMargin = 0;
bASequenceControl.overlapWidth = 22;
[self.view addSubview:bASequenceControl];
Any help on this is appreciated.
Thanks.
This is a pretty simple fix. You will have to edit the BASequenceControl.m file or you can duplicate the class and rename it.
The line that is causing the problem is in drawRect: it basically draws the grey arrow across the entire background of the control. Creating that nice gradient in the empty space.
[passiveSegmentImage drawInRect:CGRectMake(-passiveSegmentImage.size.width, 0,
w + 2 * passiveSegmentImage.size.width, h)];
You can change it to:
[passiveSegmentImage drawInRect:CGRectMake(0, 0,
w, h)];
Now you have to tell the control that it should not be opaque. Update the initializers like this.
- (void)awakeFromNib {
_selectedSegmentIndex = -1;
[self setOpaque:NO];
[super awakeFromNib];
}
- (id)init {
if ((self = [super init])) {
[self setOpaque:NO];
_selectedSegmentIndex = -1;
}
return self;
}
This is pretty quick and dirty, you could potentially make this settable with a property. Then submit a pull request to BaseAppKit, but I'll leave that to you. Here is a gist that you can copy and paste directly in BASequenceControl.m to fix the overhang.
https://gist.github.com/4632686
Edit: Make sure that you are using init as the initializer and then setFrame: (I'm not really sure why initWithFrame: wasn't overridden in the class.)
BASequenceControl *control = [[BASequenceControl alloc] init];
[control setFrame:CGRectMake(0, 0, 300, 40)];
Green background for dramatic effect
How about to use a mask like this :
to mask your SegmentedControl

iPhone - What is the correct way to implement the UIScrollView?

I have two UIViewControllers each with their own nib files. Each controller serves a different purpose. The idea was to add a UIScrollController and add both UIViewControllers to it so the user can easily scroll between them both.
Q1) Is this even possible? Or have I got the whole purpose of UIScollControllers incorrect, if so, what is the best alternative.
I have been poking around the internet and the best I can come up with is this:
ScoreViewController *scoreController = [[ScoreViewController alloc] initWithNibName:#"ScoreViewController" bundle:nil];
scoreController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
[self.scrollview addSubview:scoreController.view];
[scoreController release];
SettingsViewController *settingsController = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
settingsController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
[self.scrollview addSubview:settingsController.view];
[settingsController release];
This code is entered inside my RootViewController class. It doesn't seem to work though as I can't scroll between the two UIViewControllers I have added (score and settings). All what is displayed on the screen is the second controller added - the SettingsViewController.
Q2) Why is this broken?
Thank you. :)
Actually you place the first controller correctly, then you put the second above it.
settingsController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
960x640 - this is not the correct way to enter coordinates (320x480 is the actual size) double size is used only for image files
0.0f, 0.0f means x: 0, y: 0, so in the second controller you need x: 320, y: 0
then, you have to set the contentSize of the scrollView
scrollview.contentSize = CGSizeMake(320*2, 480);
Then enable the paging of the scrollView;
scrollview.pagingEnabled = YES;
And that should work :)

view.frame is not working in ipad?

I am developing iPad application in landscape mode.I have set in all view controller as return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);.
but when I give change view frame through following code,it is not changing , it occupies full screen of ipad.How can i overcome this problem , any help please?I tried view.frame also.
-(IBAction)category_Click:(id)sender
{
CGRect rect = _categoryController.view.bounds;
rect.origin.x = 0;
rect.origin.y = rect.origin.y;
rect.size.width = 1024;
rect.size.height = 650;
_categoryController.view.bounds = rect;
_categoryController.view.bounds = CGRectMake(rect.origin.x, rect.origin.y,1024, 650);
[self presentModalViewController:_categoryController animated:YES];
}
Have you tried adjusting the frame after the viewController is presented? I believe that the presentModalViewController:animated: method may sometimes alter the frame during its execution. You may even need to wait until the animation is finished.
If it possible, perhaps try adjusting the view's frame in the '-(void)viewDidAppear:' method of the _categoryController's class.
Generally, though, I have found that changing the appearance of a modal view controller in a smooth way is difficult.
Check modalPresentationStyle property
_categoryController.modalPresentationStyle = UIModalPresentationFormSheet;
_categoryController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:_categoryController animated:YES];
_categoryController.view.superview.frame = CGRectMake(0, 0, 818, 739);
_categoryController.view.superview.center = self.view.center;

How to mimic the resizable StatusBar in the Spotify iOS app

I've been struggling to figure out how Spotify creates the UI for when the app goes into offline mode. They make it seem like the StatusBar has resized, but in reality they're just putting a view below, and resizing all controllers throughout the app. I've tried subclassing UINavigationController, subclassing UIWindow, resizing the window, but nothing seems to work for every case.
The interesting thing about the Spotify app, is that their solution seems to still work when iOS' own UIViewController subclasses are presented modally (as seen in the image below, showing apple's MFMailComposeViewController - you can tell it's not a custom controller because of the UIBarButtonItems).
If anyone has any insight into how this is possible, that would be awesome.
it's a very dangerous thing to do. I've done in the past and I had nightmares. Below the code that works in iOS4 and supports orientation changes.
- (void) _adjustViewControllerforTicker {
TickerView* vv = [ApplicationContext getTickerView];
if ([PreferenceDataModel isFxTickerOn]&& self.navigationController.view.frame.origin.y==0) {
CGRect tableRect = self.tableView.frame;
self.tableView.frame = CGRectMake(tableRect.origin.x,tableRect.origin.y, tableRect.size.width, tableRect.size.height -20);
UINavigationController *nav = self.navigationController;
CGRect gframe = CGRectOffset(self.navigationController.view.frame, 0, 20);
self.navigationController.view.frame = gframe;
if (!vv) {
vv = [[TickerView alloc] initWithFrame:CGRectMake(0, 0, 480, 20)];
[nav.view addSubview:vv];
[vv release];
self.tableView.contentInset=UIEdgeInsetsMake(0,0,20.0,0.0);
[ApplicationContext setTickerView:vv];
}
if (![PreferenceDataModel isTickerOn]) {
self.tableView.contentInset= UIEdgeInsetsZero;
if (vv){
[vv removeFromSuperview];
vv=nil;
[ApplicationContext setTickerView:nil];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self _adjustViewControllerforTicker];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self _adjustViewControllerforTicker];
TickerView* vv = [ApplicationContext getTickerView];
if ([vv count]) {
[vv startAnimation];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self _adjustViewControllerforTicker];
}
And this is how it looks:

iOS willRotateToInterfaceOrientation proper usage

I have a very simply UIViewController, and I'm trying to figure out how to use willRotateToInterfaceOrientation. my UIViewController has a very simple viewDidLoad method:
-(void)viewDidLoad {
[super viewDidLoad];
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
theBar.tintColor = [UIColor orangeColor];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"The Title"];
item.hidesBackButton = YES;
[theBar pushNavigationItem:item animated:YES];
[item release];
[self.view addSubview:theBar];
}
So basically, I just have a UINavigationBar at the top of my controller. That's it. I implemented some methods for rotation, based on what I found online:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 640, 48)];
}
}
So, I launch the app in portrait mode, and then I twist in in landscape mode. And basically, theBar still stays it's normal size, and doesn't get resized. I'm sure this is a silly question, but what is the proper way to use the rotation capability? I want to make it so that it also works if the app is launched in landscape mode. What is the best way to initialize my components when the UIViewController first launches, keeping in mind that I want support for both orientations, and also keeping in mind that I want to be able to change the size of everything based on orientation changes throughout the duration of the life of the UIViewController? Thanks!
What you want to do is change the frame of your existing theBar object, and not instantiate a new one. You can do that with something like this:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation
duration:(NSTimeInterval)duration {
CGRect f = CGRectMake(0,
0,
CGRectGetWidth(self.view.frame),
CGRectGetHeight(theBar.frame);
theBar.frame = f;
}
Note that the value of self.view.frame is used, which contains values post rotation. Also note that the function I'm using here is different than yours. I haven't tested it with the function you're using, so I can't say if that'll work or not. Finally, you can avoid this altogether by just setting the autoresizingmask on theBar in viewDidLoad instead:
[theBar setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];