Moving UIImage view Dynamically when Autolayout is enabled

a 夏天 提交于 2019-12-11 18:58:56

问题


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.



来源:https://stackoverflow.com/questions/25423611/moving-uiimage-view-dynamically-when-autolayout-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!