文档视界 最新最全的文档下载
当前位置:文档视界 › ios 屏幕旋转和适配

ios 屏幕旋转和适配

ios 屏幕旋转和适配
ios 屏幕旋转和适配

// BMPViewController.m

// MyBitmapData

//

// Created by IMac_06 on 14-1-6.

// Copyright (c) 2014年IMac_06. All rights reserved. //

#import "BMPViewController.h"

#import "ColorMatrixValues.h"

@implementation BMPViewController{

@private

UIImageView *_imageView;

BitmapRGBA_Data *_originBitmapData;

UISegmentedControl *_segmentControl;

CGRect _rect;

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}

-(void)initUIITems

_rect = [[UIScreen mainScreen] bounds];

UIImage *image = [UIImage imageNamed:@"test.jpg"];

_originBitmapData = [[BitmapRGBA_Data alloc] initWithCGImage:image.CGImage];

_imageView = [[UIImageView alloc] initWithFrame:_rect];

_imageView.image = image;

[self.view addSubview:_imageView];

_segmentControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, _rect.size.height-100,

_rect.size.width, 50)];

[_segmentControl insertSegmentWithTitle:@"原始" atIndex:0 animated:NO];

[_segmentControl insertSegmentWithTitle:@"lomo" atIndex:1 animated:NO];

[_segmentControl insertSegmentWithTitle:@"黑白" atIndex:2 animated:NO];

[_segmentControl insertSegmentWithTitle:@"旧化" atIndex:3 animated:NO];

[_segmentControl insertSegmentWithTitle:@"哥特" atIndex:4 animated:NO];

[_segmentControl insertSegmentWithTitle:@"锐色" atIndex:5 animated:NO];

[_segmentControl insertSegmentWithTitle:@"淡雅" atIndex:6 animated:NO];

[_segmentControl insertSegmentWithTitle:@"酒红" atIndex:7 animated:NO];

[_segmentControl insertSegmentWithTitle:@"清宁" atIndex:8 animated:NO];

[_segmentControl insertSegmentWithTitle:@"浪漫" atIndex:9 animated:NO];

[_segmentControl insertSegmentWithTitle:@"蓝调" atIndex:10 animated:NO];

[_segmentControl insertSegmentWithTitle:@"梦幻" atIndex:11 animated:NO];

[_segmentControl insertSegmentWithTitle:@"夜色" atIndex:12 animated:NO];

[_segmentControl addTarget:self

action:@selector(segmentControlEvent:) forControlEvents:UIControlEventValueChanged];

_segmentControl.backgroundColor = [UIColor lightGrayColor];

[_segmentControl setTintColor:[UIColor blackColor]];

[self.view addSubview:_segmentControl];

[self.view bringSubviewToFront:_segmentControl];

}

-(void)segmentControlEvent:(UISegmentedControl *)sgc {

printf("clicked the %d

sgment\n",sgc.selectedSegmentIndex);

BitmapRGBA_Data *bitmapData = [[BitmapRGBA_Data alloc]

initWithBitmapData:_originBitmapData];

RGBAColorMatrix *colorMatrix =

s_ColormatrixArray[sgc.selectedSegmentIndex];

[bitmapData processWithColorMatrix:colorMatrix];

UIImage *image = [bitmapData convertToImageCopyData:YES];

_imageView.image = image;

}

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view.

[self initUIITems];

}

#pragma mark -----设置旋转功能-----------

#if 0

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfac eOrientation)toInterfaceOrientation

{

return toInterfaceOrientation;

}

#endif

#if 1

/*以前的方法不调用,改为下面的方法,并追加了一个NSUInterger返回值的方法*/

-(BOOL)shouldAutorotate

{

return YES;

}

-(NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortraitUpsideDown|UIInterface OrientationMaskPortrait|UIInterfaceOrientationMaskLandsca peLeft|UIInterfaceOrientationMaskLandscapeRight;

}

#endif

#pragma mark ----屏幕旋转后调用函数-------

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfa ceOrientation)toInterfaceOrientation

duration:(NSTimeInterval)duration

{

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft||toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

_segmentControl.frame = CGRectMake(0,

_rect.size.width-100, _rect.size.height, 50);

_imageView.frame = CGRectMake(0, 0,

_rect.size.height, _rect.size.width);

}else{

_segmentControl.frame = CGRectMake(0,

_rect.size.height-100, _rect.size.width, 50);

_imageView.frame = CGRectMake(0, 0,

_rect.size.width, _rect.size.height);

}

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

相关文档