Wednesday, 23 February 2011
Hide UITabBarController/UITabBar with animation.
UITabBarController *tabBarController;
- (void) hidetabbar {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
[UIView commitAnimations];
hiddenTabBar = !hiddenTabBar;
}
//Taken from https://sites.google.com/a/injoit.com/knowledge-base/for-developers/graphics/hide-uitabbarcontroller-uitabbar-with-animation
Wednesday, 29 December 2010
How to make infinite-like UIScrollView
#define WIDTH_OF_IMAGE 63
#define HEIGHT_OF_IMAGE 70
- (void)viewDidLoad {
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 341,320,HEIGHT_OF_IMAGE)];
scrollView.showsHorizontalScrollIndicator=NO;
[self.view addSubview:scrollView];
[self setupScrollView];
}
-(void) setupScrollView{
scrollView.bounces = YES;
//scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.userInteractionEnabled = YES;
slideImages = [[NSMutableArray alloc] init];
[slideImages addObject:@"activity_01.png"];
[slideImages addObject:@"activity_02.png"];
[slideImages addObject:@"activity_03.png"];
[slideImages addObject:@"activity_04.png"];
[slideImages addObject:@"activity_05.png"];
[slideImages addObject:@"activity_06.png"];
[slideImages addObject:@"activity_07.png"];
[slideImages addObject:@"activity_08.png"];
[slideImages addObject:@"activity_09.png"];
// add all of the images to the scroll view
for (int i =0; i < [slideImages count]; i++) {
[self addImageWithName:[slideImages objectAtIndex:i] atPosition:i];
}
for (int i =0; i < [slideImages count]; i++) {
[self addImageWithName:[slideImages objectAtIndex:i] atPosition:i+[slideImages count]];
}
for (int i =0; i < [slideImages count]; i++) {
[self addImageWithName:[slideImages objectAtIndex:i] atPosition:i+2*[slideImages count]];
}
scrollView.contentSize = CGSizeMake((3*[slideImages count])*WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE);
[scrollView scrollRectToVisible:CGRectMake(WIDTH_OF_IMAGE,0,WIDTH_OF_IMAGE,HEIGHT_OF_IMAGE) animated:NO];
}
- (void)addImageWithName:(NSString*)imageString atPosition:(int)position {
// add image to scroll view
UIImage *image = [UIImage imageNamed:imageString];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(position*(WIDTH_OF_IMAGE+LEFT_EDGE_OFSET), 0, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE);
[scrollView addSubview:imageView];
[imageView release];
}
//Moving the scroll view to the desired offset
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1{
if (scrollView1.contentOffset.x <=([slideImages count]-1)*WIDTH_OF_IMAGE) {
[scrollView setContentOffset:CGPointMake(([slideImages count]+([slideImages count]-1))*WIDTH_OF_IMAGE, 0)];
}
else if (scrollView1.contentOffset.x >=(2*([slideImages count]))*WIDTH_OF_IMAGE) {
[scrollView setContentOffset:CGPointMake(([slideImages count])*WIDTH_OF_IMAGE, 0)];
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView1{
if (scrollView1.contentOffset.x <=([slideImages count]-1)*WIDTH_OF_IMAGE) {
[scrollView setContentOffset:CGPointMake(([slideImages count]+([slideImages count]-1))*WIDTH_OF_IMAGE, 0)];
}
else if (scrollView1.contentOffset.x >=(2*([slideImages count]))*WIDTH_OF_IMAGE) {
[scrollView setContentOffset:CGPointMake(([slideImages count])*WIDTH_OF_IMAGE, 0)];
}
}
Ready for questions!!!
Monday, 6 September 2010
Distribute application wirelessly
Sunday, 5 September 2010
ModalViewController full screen solution
-(void)showModalViewController{
ModalViewControllerView *modelViewController=[[ModalViewControllerView alloc] initWithNibName:@"ModalViewControllerView" bundle:nil andmainView:mainViewController];
[ModalViewControllerView.view setBackgroundColor:[UIColor clearColor]];
[self presentModalViewController: ModalViewControllerView animated:YES];
}
now, in ModalViewControllerView class, add these lines to the init method
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andmainView:mainViewController{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// send the mainView back to work as a background
[self.view sendSubviewToBack:mainViewController.view];
// it takes sometime to load the view. So, using NSTimer to load it
NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:0.42 target:self selector:@selector(add) userInfo:nil repeats:NO];
}
return self;
}
-(void)add{
// Using the following lines, it'll allow you to to interaction with the mainView even when there is a ModalViewController in the front
[self.view addSubview:mainViewController.view];
[self.view sendSubviewToBack:mainViewController.view];
}
have a nice time!!!
Saturday, 4 September 2010
Who we are?
Wait out solutions...