Monday, June 18, 2012

UIView class methods for common animations.



Following  UIView class  methods are convenience methods for common animations.

UIView Animation blocks

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.70];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        
Your Code to change the position of UIVeiw goes here...
        
[UIView commitAnimations];


We can animate UIView in ios 5 using this simple code. 

[UIView animateWithDuration:0.5
                              delay:1.0
                            options: UIViewAnimationCurveEaseOut
                         animations:^{
                             view.contentOffset = CGPointMake(position, 0.0f);
                         }
                         completion:^(BOOL finished){
                             NSLog(@"Done!");
                         }];

Wednesday, June 13, 2012

Method to insert text to a UITextView.


Method to insert text to a UITextView.

- (void)insertTextToTextView:(NSString *)string
{
    if ([self.textView.text length]== 0)// Nothing in the textview
    {
        NSString *textViewString = [[NSString alloc] initWithFormat:@"%@%@",textView.text, string];
        [textView setText:textViewString];
    }
    else
    {
        NSRange range = textView.selectedRange;
        NSString *firstHalfString = [textView.text substringToIndex:range.location];
        NSString *secondHalfString = [textView.text substringFromIndex:range.location];
        textView.text = [NSString stringWithFormat:@"%@%@%@",firstHalfString,string,secondHalfString];
        textView.selectedRange = NSMakeRange(firstHalfString.length+string.length,0);
       
    }
}

QuartzCore Framework

If You get this kind of compile error,

Property 'anchorPoint' cannot be found in forward class object 'CALayer'

Solution:

Most likely, the error is caused because the QuartzCore  Framework is not added to the project.

To do this, select the project in the left sidebar and then select Target and then the Build Phases tab on the right pane. Expand the “Link Binary with Libraries” section and then click on the + sign and look for QuartzCore to add it.

Don't forget to Import the QuartzCore to your .m file.

Use this code. #import <QuartzCore/QuartzCore.h>

Done. :)