2013-05-21 23 views
0

在此应用程序中,从纵向模式开始。弹出取向更改

enter image description here

enter image description here

代码片段

NSInteger heightOne; 
    NSInteger heightTwo; 
    NSInteger imgV; 
    CGRect Bounds = [[UIScreen mainScreen] bounds]; 
if (Bounds.size.height == 568) { 
    // code for 4-inch screen 
    heightOne = 480+38; 
    heightTwo = 240+38;//370 
    imgV = 360; 

} else { 
    // code for 3.5-inch screen 
    heightOne = 480; 
    heightTwo = 240;//330 
    imgV = 310; 

} 

UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(00, 00,320,heightOne)]; 
firstView.opaque = NO; 
firstView.tag = 1000; 
firstView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f]; 
[self.view addSubview:firstView]; 



UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(250,imgV,50,50)]; 
img.image = [UIImage imageNamed:@"Zoom.jpg"]; 
[firstView addSubview:img]; 

UIView *secondView= [[UIView alloc] initWithFrame:CGRectMake(0,0,320,heightOne)]; 
[secondView setBackgroundColor:[UIColor clearColor]]; 
[firstView addSubview:secondView]; 

UIView *thirdView = [[UIView alloc] initWithFrame:CGRectMake(15,60,290,heightTwo)];//30 
[thirdView setBackgroundColor:[UIColor whiteColor]]; 
thirdView.layer.cornerRadius = 2.0f; 
thirdView.layer.borderWidth = 4.0f; 
thirdView.layer.borderColor = [UIColor colorWithRed:0.0/255.0 green:100.0/255.0 blue:0.0/255.0 alpha:1.0].CGColor; 
[secondView insertSubview:thirdView atIndex:0];  


///////////////////////////// Creating custom close button //////////////////////////////// 


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setFrame:CGRectMake(287,48,30,30)];//24 
[button setBackgroundImage:[UIImage imageNamed:@"Close-Gr.png"] forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(dismissOverViewController) forControlEvents:UIControlEventTouchUpInside]; 
button.backgroundColor = [UIColor clearColor]; 
[secondView insertSubview:button aboveSubview:thirdView]; 
secondView.frame = CGRectMake(0,0,320,480); 
[UIView animateWithDuration:0.3 
       animations:^{ 
        secondView.frame = CGRectMake(0,0,320,480); 
       }]; 


[thirdView setBackgroundColor:[UIColor grayColor]];   

}

这里我只需要弹出旋转。任何参考文献的链接或建议,真的很感谢。

+0

设定弹出的帧中取向方法时在横向的旋转装置 – Rushabh

回答

5

返回任何经由本地通知

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

拉手装置旋转: -

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(didRotate:) 
              name:UIDeviceOrientationDidChangeNotification 
              object:nil]; 

和旋转,只要你想的看法: -

self.theView.transform = CGAffineTransformIdentity; 
self.theView.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); 

愿这帮助你。

1

请viewdidlod注册旋转通知

  • (无效)viewDidLoad中

{

UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 

if (currentOrientation == UIInterfaceOrientationLandscapeLeft || currentOrientation == UIInterfaceOrientationLandscapeRight) 
    [self willRotateToLandscape]; 
else 
    [self willRotateToPortrait]; 


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateToLandscape) name:@"Interface will rotate to landscape" object:nil]; 


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateToPortrait) name:@"Interface will rotate to portrait" object:nil]; 

}

//然后调整弹出视图大小以下功能。 - (无效)willRotateToLandscape { } - (无效)willRotateToPortrait { }