使用Autolayout更改UIView的位置

时间:2015-08-06 09:59:16

标签: ios animation uiview uiinterfaceorientation

我在笔尖中设计了一个UIView类。在按钮上单击我将UIView显示为带动画的自定义弹出窗口。

以下是代码:

UIView* pickerView = [dataLoaderView newAnimationCurvePicker:self];
          //Animation will Start from middle of View
          pickerView.center = self.view.center;
          [self.scrollView addSubviewWithZoomInAnimation:pickerView duration:0.5 option:curveValues[0]];

DataLoaderView是一个UIView类

+(id) newAnimationCurvePicker:(id)pickDelegate
{
    UINib *nib = [UINib nibWithNibName:@"dataLoader" bundle:nil];
    NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
    dataLoaderView *me = [nibArray objectAtIndex:0];
return me
}

动画代码:

- (void) addSubviewWithZoomInAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option
{
    // first reduce the view to 1/100th of its original dimension
    CGAffineTransform trans = CGAffineTransformScale(view.transform, 0.01, 0.01);
    view.transform = trans; // do it instantly, no animation
    [self addSubview:view];
    // now return the view to normal dimension, animating this tranformation
    [UIView animateWithDuration:secs delay:0.0 options:option
        animations:^{
            view.transform = CGAffineTransformScale(view.transform, 100.0, 100.0);
        }
        completion:nil];    
}

我的问题是当我改变屏幕的方向时,我无法将UIView正确放置在视图的中心

-(void) viewWillLayoutSubviews
{
 if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {        
      UINib *nib = [UINib nibWithNibName:@"dataLoader" bundle:nil];
        NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
        dataLoaderView *me = [nibArray objectAtIndex:0];
        me.center = self.view.center;
    }
}

此代码对我不起作用。出于某些原因,我不允许使用自动布局

0 个答案:

没有答案