设置
问题
只要按下第二个按钮,我的视图位置就会按故事板中的定义返回。 这是我的代码:
ViewController.h
@interface ViewController : UIViewController<UIActionSheetDelegate>
@property (strong, nonatomic) IBOutlet UIView *view1;
- (IBAction)move:(id)sender;
- (IBAction)bringPop:(id)sender;
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
//move _View1
- (IBAction)move:(id)sender {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
_view1.layer.frame= CGRectMake(0, 79, 320, 489);
} completion:nil];
}
//action sheet pops
- (IBAction)bringPop:(id)sender {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"0" otherButtonTitles:@"1", @"2", @"3", nil];
[popupQuery showInView:self.view];
}
@end
答案 0 :(得分:0)
您正在设置视图的图层框架,而不仅仅是视图框架
动画块应为
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
_view1.frame= CGRectMake(0, 79, 320, 489);
} completion:nil];
答案 1 :(得分:0)
您可能需要覆盖方法
-(void)layoutSubviews
当AutoLayout或AutoResizingMasks不执行您需要的布局时,应该覆盖此方法。我非常确定UIActionSheet将自己呈现为一个modalViewController,它会在您的实际ViewController中触发viewDidAppear和viewWillAppear。
尝试设置一些断点并检查是否触发了此方法,然后AutoLayout或AutoResizingMasks重置帧,就像在xib文件中一样。
这将在很大程度上取决于您如何构建您的观点