Thursday, March 3, 2011

Changing UIView’s Coordinate System




Your Ad Here


Some times in our app we want to change the coordinate system of UIView, mostly when we change the orientation of iPhone like Landscape Right or left, So that time, coordinate system as well as appearance of UIView should also change, so here is the code to do that…

        application.statusBarHidden=YES;
       
        [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
       
        myUIView = [[MyUIView alloc] initWithFrame:CGRectMake(0,0,480,320)]; //as now width and height is changed
       
        [window addSubview:myUIView];
       
        CGAffineTransform transform=CGAffineTransformIdentity;
        transform=CGAffineTransformRotate(transform, (90.0f*22.0f)/(180.0f*7.0f));
        transform=CGAffineTransformTranslate(transform, 80, 80);
        [myUIView setTransform:transform];

Now all your subview’s of myUIView will also get transformed. and you will get CGPoint’s of new coordinate system on touch events.

No comments:

Post a Comment

 
Submit Express Inc.Search Engine Optimization Services