I have the following code to show a little notification bar right above a UITabViewController:
- (void)showNotificationBar
{
if(mentionsButton.hidden)
{
//DM button on the left
[dmButton setFrame:CGRectMake(20,-2, 140, 35)];
[directMessagesPill setFrame:CGRectMake(6, 7, 29, 20)];
[dmCountLabel setFrame:CGRectMake(11, 5, 19, 21)];
[directMessagesLabel setFrame:CGRectMake(43, 6, 81, 21)];
//Mentions on the right
[mentionsButton setFrame:CGRectMake(162,-2, 140, 35)];
[mentionsPill setFrame:CGRectMake(161, 7, 29, 20)];
[mentionCountLabel setFrame:CGRectMake(166, 6, 19, 21)];
[mentionsLabel setFrame:CGRectMake(193, 6, 86, 21)];
}
else
{
//Mentions on the left
[mentionsButton setFrame:CGRectMake(20,-2, 140, 35)];
[mentionsPill setFrame:CGRectMake(6, 7, 29, 20)];
[mentionCountLabel setFrame:CGRectMake(11, 5, 19, 21)];
[mentionsLabel setFrame:CGRectMake(43, 6, 81, 21)];
//DM on the right
[dmButton setFrame:CGRectMake(162,-2, 140, 35)];
[directMessagesPill setFrame:CGRectMake(161, 7, 29, 20)];
[dmCountLabel setFrame:CGRectMake(166, 5, 19, 21)];
[directMessagesLabel setFrame:CGRectMake(193, 6, 86, 21)];
}
if(!mentionsButton.hidden && !dmButton.hidden)
notificationDivider.hidden = NO;
if(!self.tabBarController.tabBar.hidden)
{
//CGRect frame = CGRectMake(0, 0, 320, 32);
CGRect frame = CGRectMake(0, 500, 320, 32);
//frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame) - frame.size.height;
frame.origin.y = self.tabBarController.tabBar.frame.origin.y;
notificationBar.frame = frame;
//[self.navigationController.navigationBar.superview insertSubview:notificationBar belowSubview:self.navigationController.navigationBar];
[self.tabBarController.tabBar.superview insertSubview:notificationBar belowSubview:self.tabBarController.tabBar];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = notificationBar.frame;
//frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
frame.origin.y -= frame.size.height;
notificationBar.frame = frame;
}];
}
else
{
CGRect frame = CGRectMake(0, 500, 320, 32);
frame.origin.y = self.navigationController.toolbar.frame.origin.y;
notificationBar.frame = frame;
[self.navigationController.toolbar.superview insertSubview:notificationBar belowSubview:self.navigationController.toolbar];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = notificationBar.frame;
frame.origin.y -= frame.size.height;
notificationBar.frame = frame;
}];
}
}
The problem is, there is a gap between this UIView and a UIToolbar when I switch tabs to a UINavigationController that hides the tabbar. How can I reposition it so that it goes down?
If i have understod your problem correctly this should do:
What I would do is to put the positioning code for the notification bar on another function, since you also insert subviews in this piece of code. You should call it form here and in the view did load methods of this UIViewController and the UINavigationController that you call.
A trick to position correctly the the notification bar without much trouble would be to use the toolbar y position as a reference, since it is updated automatically.
CGrect frame = notificationBar.frame;
frame.y = self.navigationController.toolbar.frame.origin.y - notificationBar.frame.size.height;
notificationBar.frame = frame;
I hope this helps.
Related
I am developing one application same as HairTryOn all things are done. but problem is display in following image. i want to set hair style as per customer face using blue line as per display in image.
i used the following code
testVw = [[UIView alloc]initWithFrame:CGRectMake(100,100, 100, 100)];
testVw.backgroundColor = [UIColor clearColor];
[self.view addSubview:testVw];
resizeVw = [[UIImageView alloc]initWithFrame:CGRectMake(testVw.frame.size.width-25, testVw.frame.size.height-25, 25, 25)];
resizeVw.backgroundColor = [UIColor clearColor];
resizeVw.userInteractionEnabled = YES;
resizeVw.image = [UIImage imageNamed:#"button_02.png" ];
[testVw addSubview:resizeVw];
UIPanGestureRecognizer* panResizeGesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:#selector(resizeTranslate:)];
[testVw addGestureRecognizer:panResizeGesture];
The resizeTranslate: method:
-(void)resizeTranslate:(UIPanGestureRecognizer *)recognizer
{
if ([recognizer state]== UIGestureRecognizerStateBegan)
{
prevPoint = [recognizer locationInView:testVw.superview];
[testVw setNeedsDisplay];
}
else if ([recognizer state] == UIGestureRecognizerStateChanged)
{
if (testVw.bounds.size.width < 20)
{
testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, 20,testVw.bounds.size.height);
imgvw.frame = CGRectMake(12, 12, testVw.bounds.size.width-24, testVw.bounds.size.height-27);
resizeVw.frame =CGRectMake(testVw.bounds.size.width-25, testVw.bounds.size.height-25, 25, 25);
rotateVw.frame = CGRectMake(0, testVw.bounds.size.height-25, 25, 25);
closeVw.frame = CGRectMake(0, 0, 25, 25);
}
if(testVw.bounds.size.height < 20)
{
testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, testVw.bounds.size.width, 20);
imgvw.frame = CGRectMake(12, 12, testVw.bounds.size.width-24, testVw.bounds.size.height-27);
resizeVw.frame =CGRectMake(testVw.bounds.size.width-25, testVw.bounds.size.height-25, 25, 25);
rotateVw.frame = CGRectMake(0, testVw.bounds.size.height-25, 25, 25);
closeVw.frame = CGRectMake(0, 0, 25, 25);
}
CGPoint point = [recognizer locationInView:testVw.superview];
float wChange = 0.0, hChange = 0.0;
wChange = (point.x - prevPoint.x); //Slow down increment
hChange = (point.y - prevPoint.y); //Slow down increment
testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, testVw.bounds.size.width + (wChange), testVw.bounds.size.height + (hChange));
imgvw.frame = CGRectMake(12, 12, testVw.bounds.size.width-24, testVw.bounds.size.height-27);
resizeVw.frame =CGRectMake(testVw.bounds.size.width-25, testVw.bounds.size.height-25, 25, 25);
rotateVw.frame = CGRectMake(0, testVw.bounds.size.height-25, 25, 25);
closeVw.frame = CGRectMake(0, 0, 25, 25);
prevPoint = [recognizer locationInView:testVw.superview];
[testVw setNeedsDisplay];
}
else if ([recognizer state] == UIGestureRecognizerStateEnded)
{
prevPoint = [recognizer locationInView:testVw.superview];
[testVw setNeedsDisplay];
}
}
This code Resizing full view. but i want to Resize only those part which is moved by finger.
I don't see how your primitives are constructed. But you will need to partition your point set according to touch zones and scale then as needed. If you convert your lines into Bezier curves, then manipulating the curve will be easier, as you will not need to do terrible amount of adjustment to the shape with a small modifications.
I wonder if anyone could kindly assist, I am trying to adjust my app so that it recognises the full screen of the iPhone 5, it all works fine on other screens now, however my initial screen I am having an issue with, as I fade the top and bottom bars out of view, the top works fine however the bottom does not, could anyone assist with the code to help me get it to work on the iPhone 5? As right now, the bar is too high on the screen on iPhone 5 and does not fade out of view...
- (void)barwillGo
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 320, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 430, 320, 50)];
}
else {
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 481, 320, 50)];
}
}
completion:nil];
}
else {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 768, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 768, 50)];
[bottomBar setFrame:CGRectMake(0, 974, 768, 50)];
}
else {
[topBar setFrame:CGRectMake(0, -51, 768, 50)];
[bottomBar setFrame:CGRectMake(0, 1025, 768, 50)];
}
}
completion:nil];
}
}
You hard coded the CGRect values of the bottomBar to the 3.5 inch screen dimensions.
Try something like this within your first animation block:
CGRect bounds = topView.superview.bounds;
CGFloat topRectY, bottomRectY;
if(topBar.frame.origin.y == -50){
topRectY = 0;
bottomRectY = bounds.size.height - 50;
} else {
topRectY = -50;
bottomRectY = bounds.size.height;
}
topBar.frame = CGRectMake(0, topRectY, bounds.size.width, 50);
bottomBar.frame = CGRectMake(0, bottomRectY, bounds.size.width, 50);
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 320, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 430, 320, 50)];
}
else {
//check device iphone5 or not
if (screenHeight != 568.0f) {
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 481, 320, 50)];
}
else
{
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 569, 320, 50)];
}
}
}
completion:nil];
}
Am working in an iPhone app using UITextView. I am trying to increase the height of UITextView based on it's content length. It is working fine. But, when the height of uitextview increase the UITextView should change the height in up side not increase height in down.
This is the code am trying in my project,
baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 50)];
baseView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:baseView];
TextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 40)];
TextView.backgroundColor = [UIColor whiteColor];
TextView.layer.borderWidth = 2;
TextView.delegate = self;
TextView.font = [UIFont fontWithName:#"Helvetica" size:16];
[baseView addSubview: TextView];
-(void)textViewDidChange:(UITextView *)textView
{
CGRect frame = messageTextView.frame;
frame.size.height = messageTextView.contentSize.height;
TextView.frame = CGRectMake(20, 10, 280, frame.size.height);
baseView.frame = CGRectMake(0, 50, 320, frame.size.height+20);
}
When the UITextView height is changing the effect textview height will be increase on top side. Can anyone please help me on this? Thanks in advance.
In the method you change the frames, also edit the frame.origin.y value of the textView
-(void)textViewDidChange:(UITextView *)textView
{
CGRect frame = messageTextView.frame;
frame.size.height = messageTextView.contentSize.height;
TextView.frame = CGRectMake(20, 0, 280, frame.size.height); //previous y was 10
baseView.frame = CGRectMake(0, 50, 320, frame.size.height+20);
}
Nonetheless, I believe you are aware that you have only 10 pixels for the textView to go up, as you are adding it to a BaseView view.
I have a little problem, I try to display a view with an animation in this way:
self.vistaAiuti = [[UIView alloc] initWithFrame:CGRectMake(10, -200, 300, 200)];
self.vistaAiuti.backgroundColor = [UIColor blueColor];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeButton.frame = CGRectMake(50, 140, 220, 40);
[closeButton setTitle:#"Go back" forState:UIControlStateNormal];
[closeButton addTarget:self action:#selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
[self.vistaAiuti addSubview:closeButton];
[self.view addSubview:self.vistaAiuti];
[UIView beginAnimations:#"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5f];
self.vistaAiuti.frame = CGRectMake(10, 0, 300, 200);
[UIView commitAnimations];
and this for close it:
[UIView beginAnimations:#"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5f];
self.vistaAiuti.frame = CGRectMake(10, -200, 300, 0);
[UIView commitAnimations];
the problem is that the button on vista aiuto is slower then the vistaAiuti, so when I close the view the button remains behind for some second...what I have to do for for have the same velocitiy?
The problem is that the vistaAiuti frame is being set to zero height in the close animation. The button appears to lag, but what's really happening is that the parent view underneath is shrinking to zero height and -200 origin.y.
Change the close animation target frame to:
self.vistaAiuti.frame = CGRectMake(10, -200, 300, 200);
Also, some other advice:
Separate the creation of the view from showing it. This way you don't add another subview every time you want to show it.
- (void)addVistaAiutiView {
// your creation code
self.vistaAiuti = [[UIView alloc] initWithFrame:CGRectMake(10, -200, 300, 200)];
self.vistaAiuti.backgroundColor = [UIColor blueColor];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeButton.frame = CGRectMake(50, 140, 220, 40);
[closeButton setTitle:#"Go back" forState:UIControlStateNormal];
[closeButton addTarget:self action:#selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
[self.vistaAiuti addSubview:closeButton];
[self.view addSubview:self.vistaAiuti];
}
Use block animation, it's much more compact to write and easy to read
- (BOOL)vistaAiutiIsHidden {
return self.vistaAiuti.frame.origin.y < 0.0;
}
- (void)setVistaAiutiHidden:(BOOL)hidden animated:(BOOL)animated {
if (hidden == [self vistaAiutiIsHidden]) return; // do nothing if it's already in the state we want it
CGFloat yOffset = (hidden)? -200 : 200; // move down to show, up to hide
NSTimeInterval duration = (animated)? 0.5 : 0.0; // quick duration or instantaneous
[UIView animateWithDuration:duration animations: ^{
self.vistaAiuti.frame = CGRectOffset(0.0, yOffset);
}];
}
I created a button, with a custom image and displayed it in a frame.
Now I'm trying to change the button's frame, inside an animation block.
Unfortunately, it doesn't seem to work - the frame doesn't change as expected.
I have written the following code:
UIButton *movingButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
UIImage *image = [UIImage imageNamed:#"A_normal_image.png"];
[movingButton setImage:image forState:UIControlStateNormal];
movingButton.frame = CGRectMake(160, 240, 0, 0);
[movingButton addTarget:self action:#selector(moveButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:movingButton];
CGRect newFrame CGRectMake(20, 120, 44, 88);
[UIView animateWithDuration:0.5 animations:^{ movingButton.frame = newFrame; }];
[movingButton release];
Am I missing something? How should I do that then?
Thanks in advance,
Sagiftw
You should use floats instead of ints:
movingButton.frame = CGRectMake(160, 240, 0, 0);
to:
movingButton.frame = CGRectMake(160.0f, 240.0f, 0.0f, 0.0f);