Thursday 30 January 2014

Transition like app launch in iOS 7.. Show and hide view as the app open up in iOS 7..

//Show animation-------
loginViewController.view.frame = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame. size.height);
loginViewController.view.transform = CGAffineTransformMakeScale(0.0001, 0.0001);
loginViewController.view.layer.anchorPoint = CGPointMake(0, 0);
loginViewController.view.layer.position = CGPointMake(0, 0);
[UIView animateWithDuration:0.6f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
loginViewController.view. transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished){

}];



//Hide animation-------
loginViewController.view.layer.anchorPoint = CGPointMake(0, 0);
loginViewController.view.layer.position = CGPointMake(0, 0);
[UIView animateWithDuration:0.6f delay:0 options:UIViewAnimationOptionAllowUserInteraction   animations:^{
// loginViewController. view.alpha = 0.0f;
loginViewController. view. transform = CGAffineTransformMakeScale(0.0001, 0.0001);
} completion:^(BOOL finished)
{
//NSLog(@"sliding finished...");
[loginViewController removeFromParentViewController];
[loginViewController. view removeFromSuperview];

}];


Change the anchor point and position, to try different animations..



Friday 24 January 2014

Decrease the clickable area of the bar buttons in navigation bar.

Some the you need to add the buttons just below UINavigationbar, but the UIBarButton on navbar click area interfere with your custom button click area.





I added hitTest:withEvent:  code to my  custom UINavigationbar subclass..


-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
            int errorMargin = 5;// space left to decrease the click event area
            CGRect smallerFrame = CGRectMake(0 , 0 - errorMargin, self.frame.size.width, self.frame.size.height);
            BOOL isTouchAllowed =  (CGRectContainsPoint(smallerFrame, point) == 1);
           
            if (isTouchAllowed) {
                self.userInteractionEnabled = YES;
            } else {
                self.userInteractionEnabled = NO;
            }
            return [super hitTest:point withEvent:event];
        }
}

Read More

Friday 3 January 2014

Crop and resize UIImage to fit from centre.


For showing the image in UIImageView to fit in the frame from centre, set two properties of UIImageView.

1.) UIViewContentMode:
    [self.myImageView setContentMode:UIViewContentModeScaleAspectFill];
- This will make image to be maintain its original width and height ratio.(Aspect)

2.) clipsToBounds
    [self.myImageView setClipsToBounds:YES];
- This will clip the image part which is going outside the UIImageView's frame. 

So both UIViewContentMode and clipsToBounds will make the image to crop from the centre and will maintain the original width and height ratio of image.







Refer this StackoverFlow post.