CGRect frame = bottomView.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height + 88;
bottomView.frame = frame;
NSLog(#"bottom view frame is %f", bottomView.frame.origin.y);
[UIView commitAnimations];
[self bottomButtonsCustomLoad];
I also have the line
frame.origin.y = [UIScreen mainScreen].bounds.size.height + 88;
nested inside an "If" statement and both log 579 which should display the view but the one inside the if statement the uiview isn't visible it logs 579 but isn't there it seems to be below the window which is where it starts before animation
If you set the y origin to the height of the screen it seems normal that your view is not visible, since it'll be outside of the screen (at the bottom).
Remember the point (0,0) is the top left corner.
The code you show puts the window at 88 points below the bottom edge of the screen, so it seems right that it does not show. If you meant for the view to be 88 points below the top edge, it should be
frame.origin.y = 88
Related
i want draw a wave line with 4500 points when the finger moves,but I don't want to make my view 4500 wide.
In my limited experience , my idea is when the finger moves , increase width of the View and then draw the new increase rectangle use -setNeedsDisplayInRect:
CGRect frame = self.frame;
frame.size.width +=568;
self.frame = frame;
[self setNeedsDisplayInRect:CGRectMake(568* self.currentPage, 0, 568, self.bounds.size.height)];
the result is :
But if i didn't change the frame of the view,it works fine:
For this problem,I am searching for a long time on net. But no use.
What happened when I change the frame Of my view?
Try:
CGRect frame = self.bounds;
instead of CGRect frame = self.frame;
What I'm trying to reach is similar to what is implemented on youTube app on iPad. The search field is expanding in animation from right to left. I'm trying to do so and i'm getting very strange and not smooth animation, Although left to right is working perfect.
|<-------------------------------|Search Field|
It seems that the origin value is changed first and than the width changed , un like the left-right expanding animation that the origin stays the same.
Thanks
You can use animation just put Search field in dynamically in view and put below code.
[UIView beginAnimations : #"Display notif" context:nil];
[UIView setAnimationDuration:0.30];
[UIView setAnimationBeginsFromCurrentState:FALSE];
CGRect frGnrVw = generalView.frame;
CGRect frTblNote = tblNotes.frame;
frGnrVw.size.height = 0.0;
frGnrVw.size.height += 78.0;
generalView.frame = frGnrVw;
[UIView commitAnimations];
In above code general view is my view which has hight 0 and when some action called at that time view height increase and and we will see that view expanding down in that i can not change view's x and y position But in your case first hide your view and when search action calls set hidden NO of your view and in my code i increase height so you can increase your width and also change it's x position means (decrese) i.e you increase width 320 than you decrese it x position to 320 .
just try it it will work.
you can also put it statically in your story board or in nib just set its width =0 and x= 320.
you have to do like below.
[UIView beginAnimations : #"Display notif" context:nil];
[UIView setAnimationDuration:0.30]; // set duration of animation in seconds.
[UIView setAnimationBeginsFromCurrentState:FALSE];
CGRect frGnrVw = generalView.frame; //get frame of view.
frGnrVw.size.width = 0.0;
frGnrVw.size.width += 320.0;//increase width.
frGnrVw.origin.x -=320.0; // decrese position.
generalView.frame = frGnrVw; //set new frame to view.
[UIView commitAnimations]; // this will require.
you just put your view with search field at the position x=320 ,y = as your requirement ,width = 0 and height = as your requirement.
try it it will work.
Also you can hide like same in reverse order.
means increase its x position and decrease its width with above code.
If my answer helps than please vote up my answer.
I'm adding a child view on top of one of my views, and animating it so that it starts at the bottom of the screen and ends up at the top of the screen by using animateWithDuration. And that all works fine except that after animateWithDuration is complete the view on top has no user interaction and the view below still has user interaction. If I remove animateWithDuration, and just start the child view at it's normal position the user interaction works how I would expect it too, which is why I think animateWithDuration is the problem.
Here's my code:
UIViewController *viewController = [[CCouponDetailViewController alloc] init];
[[viewController view] setBounds:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height * -1), viewController.view.bounds.size.width, viewController.view.bounds.size.height)];
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];
CGRect newFrame = viewController.view.frame;
newFrame.origin.x = 0;
newFrame.origin.y = ([UIScreen mainScreen].bounds.size.height * -1);
[UIView animateWithDuration:1.0
animations:^{
viewController.view.frame = newFrame;
}
completion:^(BOOL finished){
[viewController didMoveToParentViewController:self];
}
];
Another question I have (Not really important just curious) is that in newFrame I'm setting the y to the same thing as it is when I initially set the bounds, but yet it moves. I would have expected newFrame to require a y value of "0" but when I did that nothing happened. Just wondering why that is.
I'll actually go backwards on this one...
"Another question I have (Not really important just curious) is that in newFrame I'm setting the y to the same thing as it is when I initially set the bounds, but yet it moves. I would have expected newFrame to require a y value of "0" but when I did that nothing happened. Just wondering why that is."
This is actually a very important question for you to have answered, because it has a lot to do with why your code isn't working. You're misunderstanding some very important concepts.
First off, the bounds of a UIView determine its position entirely in relation to itself. The frame determines the UIView's position within its superview. In your code, you're originally setting the view's bounds, not the frame --
[[viewController view] setBounds:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height * -1), viewController.view.bounds.size.width, viewController.view.bounds.size.height)];
-- so you're not at all originally determining the view's place within its superview, only in relation to itself.
Essentially, you're ending up with a CCouponDetailViewController view with a 0x0 frame, but since you haven't specified that you want your UIView to clip its subviews, the portions of your CCouponDetailViewController view are not actually on top of their view, but visible and hanging over the UIView's bounds. The reason they aren't selectable is because they're not actually within the UIView.
So to fix this, set your UIView's initial frame instead of setting a bounds (I've editing the initial frame to start at the bottom of the screen like you're trying to do. I don't understand the height x -1 thing you're trying to do, by the way...) :
[[viewController view] setFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, viewController.view.bounds.size.width, viewController.view.bounds.size.height)];
Secondly, you're setting your new frame incorrectly. You can't set the CGRect this way:
CGRect newFrame = viewController.view.frame;
newFrame.origin.x = 0;
newFrame.origin.y = ([UIScreen mainScreen].bounds.size.height * -1);
Instead, set it using CGRectMake (And, again, I edited the y value so that the view ends up at the top of the screen like you're trying to do):
CGRect newFrame = CGRectMake(0, 0, viewController.view.frame.width, viewController.view.frame.height);
I have this UIPickerView on my Storyboard :
and here's the position based on Size Inspector :
and here's my code :
- (void)showPickerView
{
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 , 288, self.picker.frame.size.width, self.picker.frame.size.height);
self.picker.hidden = NO;
}
completion:^(BOOL finished) {
}];
}
(after trial and error) in order to be placed correctly (bottom) on 4-inch screen, I have to set 288 as Y. I have no idea where this number come from.
because if you do some a little math here you won't get that number :
iPhone screen height = 1136px, pickerview height = 216pts = 432px
if X and Y measured from TOP-LEFT (0, 0), then for 4 inch screen I should use 1136 - 432 = 704 px / 2 = 352pts. not 288pts.
but according to Size Inspector' origin, this object measured from bottom left. so, (0,0) of X and Y now measured from BOTTOM-LEFT. you still won't get that number.
plus, even worse... when I run on 3.5 inch Simulator it's not fully shown.
how to give X and Y value for UIPickerView so it will perfectly shown for both 3.5 and 4 inch retina display screen?
thank you.
The size 1136px is for full screen, you have to take in consideration that the status bar has 20px and the navigation bar has 44px so for your computation is like:
1136px - 432(picker) - 40(status bar) - 88(navigation bar) = 576; 576/2 = 288px
That's why the 288px is working for you.
if you want to give proper coordinates to your picker view you have to do something like this:
self.picker.hidden = NO;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 ,
self.view.fra.size.height
- self.picker.frame.size.height,
self.picker.frame.size.width,
self.picker.frame.size.height);
}
completion:^(BOOL finished) {
}];
But be careful, it's really important when you call this, make sure you call it in or after -viewDidAppear: is called. Due to the fact you want this piece of code to work perfect on both 3.5'' and 4 inch screens, the view won't be properly resized and the frame is not correct until this method is called, especially if you use storyboards with or xib that creates view controllers with views for 4 inch display.
Robert,
UIPicker's position is measured always from top left corner,
UIPicker co-ordinates are the co-ordinates of centre of uipicker.
For example if you give (0,0)it will show you quarter of pickerview i.e bottom right quarter.
As the uipicker height is fixed that is 216 you need Y c0-ordinate more than or=216/2=108.
And to see full width you need X co-ordinate (picker width/2 )
Best approach in my opinion is to use the bounds property of the containing view, which should be the root view of the view controller.
UIPickerView height is 216 pixels, as illustrated by this post - this value is set by default when a Picker View is initialised.
So if we take the post of danypata into consideration, but don't want to manually calculate with set values for navigation bar height, status bar height, etc... we can do something like the following:
UIPickerView *pickerView = [[UIPickerView alloc] init]; // default frame is set
float pvHeight = pickerView.frame.size.height;
float y = view.bounds.size.height - pvHeight; // the root view of view controller
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
}
completion:nil];
I want to use a UIScrollView as my main container in the app, enabling me to swipe back and forth between subviews. To achieve this, I created a UIViewController subclass with a UIScrollView IBOutlet:
In the viewDidLoad method I construct the sub-pages:
for (int i= 0; i< pageCount; i++)
{
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * i;
frame.origin.y = 0;
UIWebView* aWebView= [[UIWebView alloc] initWithFrame:frame];
[self.scrollView addSubview:aWebView];
}
When launching the app (portrait mode), everything works. That is, the UIWebViews are layed out side by side with the correct dimensions, and I can swipe back and forth between them.
When I rotate to landscape, it seems that neither the scrollview size nor the subviews are resized.
I don't know what I should do in order to resize the subviews and the scrollview itself, or at what point in code I should do anything, and I cant seem to find any examples for this.
Anyone know what to do?
[edit] Attempt to adjust sizes as suggested by mahboudz:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * pageCount, self.scrollView.frame.size.height);
for (int i= 0; i< pageCount; i++)
{
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * i;
frame.origin.y = 0;
UIWebView* view= [[self.scrollView subviews] objectAtIndex:i];
view.frame= frame;
}
}
This kind of does what I want, but has the following issues:
1) one can see the subviews grow to correct screen size upon changing orientation
2) when the current page is, for example, page 2 of 5 pages, the page is not fully visible after orientation was changed, but is off-screen by like 40 pixels
3) I get strange effects depending on whether the app is launched in portrait or landscape mode (simulator), ill try to explain:
When the app is launched in portrait mode:
The shape/border of the subviews looks messed up/offscreen, see screenshots:
http://i53.tinypic.com/21jr76x.png
when I rotate to landscape, everything looks okay, scrolling works superb. even when I rotate back to portrait, everything is great now:
http://i55.tinypic.com/if3iiw.png
When the app is launchend in landscape mode:
I get the same messed up/offscreen glitches as in portrait mode
Switching back and forth between portrait and landscape fixes this for landscape mode
BUT: Portrait mode will have the subviews with the width of the landscape mode, thus subviews are too wide
I tried to fix 1) doing the code above in willRotateToInterfaceOrientation however it completely messed up the layout.
I fixed 2) by adding the following code to didRotateFromInterfaceOrientation:
// update the scroll view to the appropriate page
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * self.currentPage;
frame.origin.y = 0;
[self.scrollView scrollRectToVisible:frame animated:NO];
Note: current page is determined in scrollViewDidScroll
I dont have any idea how to fix 3)
You would need to reset the frame size, content size and the content offset in order to get the subviews in a proper position.
CGFloat screenHeight =[UIScreen mainScreen].bounds.size.height;
CGFloat screenWidth =[UIScreen mainScreen].bounds.size.width;
self.scrollView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * numberOfPages, self.scrollView.frame.size.height);
self.scrollView.contentOffset = CGPointMake(visiblePageBeforeRotation * self.scrollView.bounds.size.width, 0);
This code should be placed in the method
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
Check as well the answer on this question:
Clean autorotation transitions in a paging UIScrollView
It has good example named Rotolling for rotating UIScrollView with paging enabled.
Hope this helps.
P.S: I am facing a problem on repositioning the center of the UIWebView on the rotation.
You need to implement viewWillRotate/viewDidRotate and make adjustments to our content size and orientation as needed.