I am building an ap in which I need to remove the present view from the superView and load another one. But the new loaded view shifts upward. Also when the firstView is again loaded, it loads perfectly.
Could anyone possible suggest something to get rid of this issue.
Following is the method I am using to flip the view to secondView
-(void) flipToBack
{
CreateMessageViewController *oSecondView = [[CreateMessageViewController alloc] initWithNibName:#"CreateMessageViewController" bundle:nil];
[self setMsgViewController:oSecondView];
[oSecondView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Thanks in advance!!
Looking forward to your kind responses.
thanks
There is not much I can tell without looking at the big picture. Check the frames in the IB to see if they are correctly set.
Is this code from your appDelegate? Does viewController have a toolbar shown on his view? Maybe your view is shifted the exact pixels your toolbar height is?
Got it.
It's happening due to the IB settings. So in IB your viewController has a statusBar and your view has a height of 460 (for iPhone) not 480. The 20 points are the statusBar height. When transitioning to the second view, its rect is {0,0,320,460} so the view is positioned behind the application's statusBar and you are missing 20 points from the bottom.
To get around this you need to:
Go into IB and set the CreateMessageViewController's statusBar to Unspecified.
Go into the view size section and set the view's height to 480 (for iPhone).
Now your CreateMessageViewController's view will show properly.
After long time playing around with the code and IB, I found the bug. It was corrected as
Open the mainWindow.xib and add the UIViewController Object from the Library. Change its class to your Class that handles the specified viewController and then comes the click. Go to the properties section of the Attribute Inspector and set the respective Nib Name for the Controller and now save and exit the IB.
And the code changes to
-(void) flipToBack
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Thanks to all who responded!!
Related
I have called a the "AppearanceWhenContainedIn" method in my AppDelegate to set the the title color of all of my buttons in Navigation Controller classes. The call is as follows:
[[UIButton appearanceWhenContainedIn:[UINavigationController class],nil] setTitleColor
[UIColor colorWithRed:0 green:0.475 blue:0.227 alpha:1] forState:UIControlStateNormal];
This works the way I want it to, however, there is one UIView where I have a button in a toolbar that I want to keep the title text of the button white (not change the color). The button and toolbar were added in my .xib file and I have the button attached to an IBAction that dismisses the modal view controller (it's an "About" view).
How would I change the text color of this specific button, or make an exception in my appearanceWhenContainedIn call?
Thank you very much for your help.
I guess in my case, because the button was in a toolbar, I used a customizeAppearance method in my AppDelegate to change the appearance of all button items in toolbars. The code was:
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"ArialMT" size:0.0],
UITextAttributeFont,
nil]
I am facing a problem in increasing the size of imageView/ view.
Actually I want my application to increase the size (0-100) of image/imageView after clicking a button through animation.
Please Help !!!
You need to create a cgrect and apply that to you view/imageview
here is a code snippet
CGRect previousFrame = view.frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5f];
previousFrame.size.width = 100;
previousFrame.size.height = 100;
view.frame = previousFrame;
[UIView commitAnimations];
paste this code on IBAction of your button. Change the code as you want. this is just for understanding the concept.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UIWebView on iPad size
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *naviController = [[UINavigationController alloc]init];
[self.view addSubview:naviController.view];
}
If I add navigation controller in the view, it appears about 20 pixels below status bar.
I want it appears just below status bar. How do I fix this?
I've experienced this same issue.
This discussion was helpful: UIWebView on iPad size
Tony's answer helped me discover this trick:
naviController.view.frame = self.view.bounds;
Turns out setting the view height fixes this problem. You can do it in the nib (xib) file or progammatically when creating the view setting the view.frame = CGRect(0, 0, 320.0 460.0); or whatever it's supposed to be (in your case it looks like it should be 460.0 since you have the status bar on).
The main point is that if the view size is smaller than the height of the screen, there are no guarantees where your controls will show up.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect frame = CGRectMake(0, 0, 320.0, 480.0);
viewController.view.frame = frame;
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
I changed like above. It works. So far so good. If height was 460, there would have been blank line at the bottom. View's absolute coordinate is (0, 20). So, Navigation bar's coordinate is (0, 40). I think that was the problem. I will encounter another problem.
Maybe there is way to change coordinate before displaying navigation view. Thank you.
Hey guys, I appear to have run into a problem. I have an application (View-based) that has a UITableView displayed on the bottom half of the screen, with the selection of a cell then bringing up a custom cell taking up the bottom of the screen. I have a "more info" button on the bottom right of this cell, and and when it is selected, I wish for it to open a new NIB file, however the only thing I can manage to do is remove the tableView from the screen..I am not sure of what to use before the "addSubview" because it is not self.view which I thought it would be.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mivc = [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self.tableview removeFromSuperview];
//[self.view addSubview:(UIView *)mivc];
[self.navigationController pushViewController:mivc animated:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"List of Events" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[mivc release];
}
Also, the (UIView *) doesn't do the trick either. Any suggestions?
P.S. The UITableView does not use a navigationController at all, it is just the table, would this be the problem?
Also, what if I chose to just push a new view, and not use the navigationViewController for this view, is this possible?
I can't answer your navigation controller question without seeing more of your program. To answer your other question, without using a navigation controller you can just add a new view with:
newViewVC = [[NewViewVC alloc]initWithNibName:#"NewViewVC" bundle:nil];
[self.view addSubview:newViewVC.view];
Typically newViewVC is declared in your .h so you can release it later.
I have found an easy way: pushing it as a modal.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mi= [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self presentModalViewController:mi animated:YES];
}
All that is needed is a back button in the new nib file.
I'm trying to scroll up my UISCrollView when the keyboard is shown
I use setContentOffset to shift the uiview up.
At the same time I want to decrease the height of my UISCrollView to (view height - keyboard height), so that the entire content view can be scrolled.
I apply both the changes in keyboardWillShow notification
When I actually bring the keyboard up in my app, the contents first get pushed up and then they are pushed down (which gives a flickering effect). I'm trying to smooth out both the transformations in one go..
Is it possible?
Code Below ---
- (void) keyboardWillShow {
CGPoint contentOffset = scrollView.contentOffset;
CGRect scrollViewFrame = scrollView.frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
if (contentOffset.y >= 0 && contentOffset.x >= 0) {
isContentOffset = YES;
contentOffset.y += screenShift;
[scrollView setContentOffset:contentOffset animated: NO];
}
scrollViewFrame.size.height = keyboardOrigin.y - self.view.frame.origin.y - toolbarHeight;
scrollView.frame = scrollViewFrame;
[UIView commitAnimations];
}
There is an option for animation when you setContentOffset for animation. here is the code that i use all the time
- (void)textViewDidBeginEditing:(UITextView *)textView
{
svos = scrollView.contentOffset;
CGRect rect = [textView bounds];
rect = [textView convertRect:rect toView:self.scrollView];
CGPoint point = rect.origin ;
point.x = 0 ;
[self.scrollView setContentOffset:point animated:YES];
doneButton.enabled = YES;
}
- (IBAction)donePressed
{
[scrollView setContentOffset:svos animated:YES];
[textview resignFirstResponder];
doneButton.enabled = NO;
}
It works fine for me.
Are you wrapping these changes in an animation block?
[UIView beginAnimations:#"resizeScroll" context:nil];
// make your changes to set and content offset
[UIView commitAnimations];
I think I have got a solution for this. You can handle the resize of the view in textViewDidBeginEditing method. You can just change the frame size of the scrollView to half by
CGRect tframe = myscrollView.frame;
tframe.size.height/=2;
myscrollView.frame = tframe;
and to initialize or handle the total length of the scrollview you can set the contentSize of the scrollView in the similar fashion as the frame was set in above snippet. for example
CGSize tsize = self.view.frame.size;
//here you can change the height and width of the scrollView
myscrollView.contentSize = tsize;
I hope this should do the trick for you. If it does please communicate.
Figured out the issue...
When the keyboard button was clicked, I was doing a becomeFirstResponder followed by a resignFirstResponder on keyboard view. This caused keyboardWillShow followed by keyboardWillHide and another keyboardWillShow notification, which brought the keyboard up, brought it back down and then up again.
Thanks to everybody who tried to help out.. and sorry the issue was pretty different...