多次激活时,保持UIButton大小相同

时间:2015-08-16 14:58:05

标签: ios objective-c uiscrollview uibutton constraints

我将UIButton约束设置为80和80的宽度和高度。但是当我按下UI按钮激活UIScrollView菜单时,约束会发生变化,按钮看起来如下图所示。 (按钮是屏幕底部的蓝色椭圆形状)

enter image description here

这是用于UI按钮和UIscrollview动画的viewwcontroller.m代码。

#import "ViewController.h"

@interface ViewController ()


@end

@implementation ViewController
@synthesize scrollView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    draw1 = 0;
    scrollView.frame = CGRectMake(0, 300, 480, 55);
    [scrollView setContentSize:CGSizeMake(480, 55)];

    openMenu.frame = CGRectMake(220, 270, 60, 30);
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    draw1 = 1;
}

- (IBAction)OpenMenu:(id)sender {
    if (draw1 ==0) {
        draw1 = 1;
        [UIView animateWithDuration:0.5
                              delay:0.0
                            options: UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             scrollView.frame = CGRectMake(0, 1000, 568, 200);
                             openMenu.layer.frame = CGRectMake(self.view.center.x - 30, self.view.frame.size.height - 80, 60, 30);
                         }
                         completion:^(BOOL finished){
                             NSLog(@"Done!");
                         }];
    } else {
        draw1 = 0;
        [UIView animateWithDuration:0.5
                              delay:0.0
                            options: UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             scrollView.frame = CGRectMake(0, 300, 568, 200);
                             openMenu.layer.frame = CGRectMake(self.view.center.x - 30, 270, 60, 30);
                         }
                         completion:^(BOOL finished){
                             NSLog(@"Done!");
                         }];
    }
}
@end

你怎么能做到这一点,按钮约束说80到80,并且在激活时不会改变?

1 个答案:

答案 0 :(得分:0)

请检查您选择的图像。我猜它的大小超过80-80。或者,它的高度>宽度。