Moving UIImage view Dynamically when Autolayout is

2019-08-27 15:36发布

问题:

i have to move a UI image view according to the the value received. I have enabled Autolayout. and i must use auto layout. Is there any other method to move my UIImage view. This is the Code i am using and i know it wont work as i have enabled Auto layout

    switch (valueForBlueBar)
     {
         case 0:
             NSLog(@"its Monday");
             break;
         case 1:
             NSLog(@"its tuesday");
             break;
         case 2:
             NSLog(@"its wednesday");
             break;
         case 3:
             NSLog(@"its thurdsay");
             [blueBarOutlet setFrame:CGRectMake(100, 100, blueBarOutlet.frame.size.width, blueBarOutlet.frame.size.height)];
             break;
         case 4:
             NSLog(@"its friday");
             break;
         default:
             break;

}

回答1:

First of all you need forget about frames if you use autolayout. As with frames you do animations inside [UIView animage....] methods.

All you need is update constraints instead frames. You can add/remove constraints or change theirs parameters or priority.



回答2:

hope this will help

when auto layout is ON you can't update the frame or bound of an ui element.You update the relevant constraints instead (you will need references to these constraints, either as outlets or as properties you've kept around after creating the constraints in code).

You can use the Autolayout Constraints tool, to make this process easier.