我试图使用以下代码来翻译一个距离的UIView:
CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(@"Begin!");
CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
[self.exposureHintView setTransform:newTrans];
}
completion:^(BOOL finished) {
NSLog(@"End %d", finished);
}];因此,基本上,我只是试图将视图从某个角度--比如(-100, -100) --转移到相对于自身而言应该是(0, 0)的位置。
由于我想在视图出现后将其动画化,所以我将代码放在viewDidAppear:中。但当我运行密码时,什么都没发生。
这里的self.exposureHintView是UIView的一个自定义子类,重要吗?
为什么?
发布于 2013-12-09 11:21:19
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[_AboutView setFrame:CGRectMake(0, 0, 320, 510)];
[UIView commitAnimations];使用此代码更改视图的位置。
发布于 2013-12-09 11:29:39
我认为这里的问题是在没有编程代码的情况下在情节提要或XIB文件中创建exposureHintView。
试着做以下几点:
- (void)viewDidLoad
{
//Init exposureHintView
UIView* exposureHintView = [[UIView alloc]initWithFrame(sampleFrame)];
[self addSubView: exposureHintView];
//Set transform
CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
//Commit animation
[UIView animateWithDuration:2.0 delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(@"Begin!");
CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
[self.exposureHintView setTransform:newTrans];
}
completion:^(BOOL finished) {
NSLog(@"End %d", finished);
}];这里的原因是当您使用故事板或XIB时,无法在UIView中设置框架或转换或>>ViewDidLoad中的其他属性。
https://stackoverflow.com/questions/20468499
复制相似问题