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.
Related
I'm trying to align an imageView at the bottom of my UIViewController, but on iPhone 5 simulator it isn't aligned on the bottom.
I've tried to put an imageView at the bottom of the storyboard and it is aligned correctly so I guess I miss something in my code.
Any advice?
Thanks,
e.
imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 416, 320, 64)];
[imageView setContentMode:UIViewContentModeScaleToFill];
imageView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:imageView];
got it, used
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:[xmlView]|"
options:0
metrics:0 views:NSDictionaryOfVariableBindings(xmlView)]];
Set the Frame Size like this:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.size.height-64, 320, 64)];
[imageView setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:imageView];
Hope this will help.
I have a UITextView with a lot of text in it. When the subview containing the UITextView is shown the UITextView only appears after the UITextView has been touched and scrolled.
Is there a limit of how much text can be in a UITextView?
Or is this a bug?
attached is a clip explaining this occurrence.
https://dl.dropbox.com/u/8256776/UITextView%20Bug.MOV
Ok, I have looked into it and it seems to be quite a common issue. It seems that the text view doesn't feel that it has to draw the text, but calling setNeedsDisplay doesn't help. I don't know if there is a "real" solution, but you can force it to draw the text by scrolling programmatically:
disclaimerView.contentOffset = CGPointMake(0, 1);
disclaimerView.contentOffset = CGPointMake(0, 0);
An unrelated thing in your code: In your switchView method you have two animations, one for the menu view and one for the view you are sliding into place. This is unnecessary as you can put both setFrame calls in the same animation:
MenuView = (UIView *)[self.view viewWithTag:100];
appView = (UIView *)[self.view viewWithTag:ViewInt];
[MenuView setFrame:CGRectMake(0, 0, 320, 480)];
[appView setFrame:CGRectMake(321, 0, 320, 480)];
[UIView beginAnimations:#"move buttons" context:nil];
[UIView setAnimationDuration:.5];
[MenuView setFrame:CGRectMake(-320, 0, 320, 480)];
[appView setFrame:CGRectMake(0, 0, 320, 480)];
disclaimerView.contentOffset = CGPointMake(0, 1);
disclaimerView.contentOffset = CGPointMake(0, 0);
[UIView commitAnimations];
And one more thing (and then I will back off :) )
You seem to be quite fond of using tags to retrieve elements. While it does work, it is not very understandable. You don't have that many elements so I would just add each of them as IBOutlet with a meaningful name (like you did with your disclaimerView). Also, have seperate switchView methods for the different views you are moving into place. That way you can easily perform additional stuff you might need for just that view, like the force scroll on disclaimerView.
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...
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!!
I want to change the UIWebView zoom level programmatically.
I have tried these but they are not worked for me ;
UIScrollView *sv = [theWebView.subviews objectAtIndex:0];
[sv setZoomScale:50 animated:YES];
also,
[theWebView stringByEvaluatingJavaScriptFromString:#"document.body.style.zoom = 5.0;"];
Any idea?
This is the only way I could find to accomplish it:
(specify your own sizes if you wish, i was attempting to zoom out after typing into a form field)
UIScrollView *sv = [[webViewView subviews] objectAtIndex:0];
[sv zoomToRect:CGRectMake(0, 0, sv.contentSize.width, sv.contentSize.height) animated:YES];
I would use:
UIScrollView * sv = self.theWebview.scrollView;
[sv setZoomScale:50];
where self is the viewController containing the webView.
Your problem could be the size of your zoomScale exceeds the size of sv.maximumZoomScale.
UIScrollView * sv = yourwebview_outlet.scrollView;
[sv setZoomScale:50];