Best Way to Perform Several Sequential UIView Animations?

If you’re willing to step up to iOS 4.0, the new blocks-based animation approach can make this animation chaining trivial. For example: [UIView animateWithDuration:1.0 animations:^{ view.position = CGPointMake(0.0f, 0.0f); } completion:^(BOOL finished){ [UIView animateWithDuration:0.2 animations:^{ view.alpha = 0.0; } completion:^(BOOL finished){ [view removeFromSuperview]; }]; }] will cause view to animate to (0, 0) over a … Read more

Need to capture UIView into a UIImage, including all subviews

That’s the right way to go: + (UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } This method is an extension method for UIImage class, and it will also take care of making the image looks good on any future high-resolution devices.

Round top corners of a UIView and add border

The mask layer doesn’t get drawn, just used to compute the mask. Try: -(void)roundCorners:(UIRectCorner)corners radius:(CGFloat)radius { CGRect bounds = self.bounds; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = bounds; maskLayer.path = maskPath.CGPath; self.layer.mask = maskLayer; CAShapeLayer* frameLayer = [CAShapeLayer layer]; frameLayer.frame = bounds; frameLayer.path = maskPath.CGPath; frameLayer.strokeColor = … Read more

“Application windows are expected to have a root view controller at the end of application launch” error only on iPad

Change the following line: [_window addSubview:[_navigationController view]]; to: _window.rootViewController = _navigationController; or, if you need iOS 3 compatibility: if ([_window respondsToSelector:@selector(setRootViewController:)]) { _window.rootViewController = _navigationController; } else { [_window addSubview:_navigationController.view]; }

How to mimic Keyboard animation on iOS 7 to add “Done” button to numeric keyboard?

In iOS 7, the keyboard uses a new, undocumented animation curve. While some have noted that using an undocumented value for the animation option works, I prefer to use the following: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; [UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue]]; [UIView setAnimationBeginsFromCurrentState:YES]; // work [UIView commitAnimations]; While block based animations are the recommendation, the animation … Read more

Different cornerRadius for each corner

Do you want to add unique corner value for each corner? Do you want to add a border after that? I’ve got a solution will look like this: First, add a UIBezierPath extension I made: extension UIBezierPath { convenience init(shouldRoundRect rect: CGRect, topLeftRadius: CGSize = .zero, topRightRadius: CGSize = .zero, bottomLeftRadius: CGSize = .zero, bottomRightRadius: … Read more

Find Frame Coordinates After UIView Transform is Applied (CGAffineTransform)

One thing to keep in mind is that the transform changes the coordinate system, so you will need to be able to convert between the parent ‘view’ and the child (transformed) view. Also, transforms preserve the center of the transformed object but not any of the other coordinates. So you need to calculate things in … Read more