Saturday, 15 February 2014

How to change the background color of UIView with delay/animation: Xcode/cocos2d

We can change the background color of an UIView with delay as follows. This can be also used for many other UIElement animations such as changing the properties of an UIButton (such as textColor) with delay/animation.


 [UIView animateWithDuration:2.0 animations:^{
    [myView setBackgroundColor:[UIColor grayColor]];
 }
    

How to set UIImageView image with delay/animation: Xcode/Cocos2d

We can set the image of an UIImageView with delay/animation as follows:


[UIView transitionWithView:myImageView
                      duration:1.0
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        myImageView.image = [UIImage imageNamed:@"newImage.png"];
                    } completion:nil];

    

Thursday, 9 January 2014

How to focus on last cell in a UITableview in Xcode



//Create a method to find out the last index of your table view and will focus to that cell with an animation:

-(void)autoFocusTableCell{
    NSIndexPath *lastIndexPath = [self lastIndexPath];
    [myTableView scrollToRowAtIndexPath:lastIndexPath
                       atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}


//Code to find the last index of your tableview.
-(NSIndexPath *)lastIndexPath{
    NSInteger lastSectionIndex = MAX(0, [myTableView numberOfSections] - 1);
    NSInteger lastRowIndex = MAX(0, [myTableView numberOfRowsInSection:lastSectionIndex] - 1);
    return [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex];
}

//Then call the method
    [self autoFocusTableCell];