I have a button with a image on it, I am using UIView.animateWithDuration to assign a new size to the view as well as the image view.
The view scales up correctly, but there is no change to the image view
Code Snippet:
@IBAction func imageButtonDidTouch(sender: AnyObject) {
UIView.animateWithDuration(0.7) {
/*** Executes Properly ***/
self.dialogView.frame = CGRectMake(0, 0, self.screenWidth!, self.screenHeight!)
/*** Does Not Execute ****/
self.imageButton.frame = CGRectMake(0, 0, self.screenWidth!, 240)
/*** Executes Properly ***/
self.likeButton.hidden = true
self.shareButton.hidden = true
self.userButton.hidden = true
self.headerView.hidden = true
self.dialogView.layer.cornerRadius = 0
}
}
Screenshot Before Button Press:

Screenshot After Button Press:

Screen Width and Screen Height Have been Defined in viewDidLoad()
screenWidth = UIScreen.mainScreen().bounds.width
screenHeight = UIScreen.mainScreen().bounds.height
EDIT 1: imageButton declaration
@IBOutlet weak var imageButton: UIButton!
EDIT 2: I added a completion handler to the animate function:
@IBAction func imageButtonDidTouch(sender: AnyObject) {
print("Height Before:", self.imageButton.frame.height)
print("Width Before:",self.imageButton.frame.width)
UIView.animateWithDuration(0.7, animations: {
/*** Executes Properly ***/
self.dialogView.frame = CGRectMake(0, 0, self.screenWidth!, self.screenHeight!)
/*** Does Not Execute ****/
self.imageButton.frame = CGRectMake(0, 0, self.screenWidth!, 240)
/*** Executes Properly ***/
self.likeButton.hidden = true
self.shareButton.hidden = true
self.userButton.hidden = true
self.headerView.hidden = true
self.dialogView.layer.cornerRadius = 0
}) { (true) in
print("Height After:", self.imageButton.frame.height)
print("Width After:",self.imageButton.frame.width)
}
}


Check before setting imageButton size wether or not are you receiving you desired screenWidth.
The right place to get the
UIScreenframe data is inviewDidLayoutSubviewsas it is called after the subViews have been laid out in screen also it is called after every time your device changes orientation such as your width will be different when your user goes into landscape mode.This is called afterviewWillAppear:Then:-
If you are initialising and declaring your button Programatically :
If you are using AutoLayout for the constraints, then :-
Create an
@IBOutletof your button's width constraint in your classThen set it accordingly.
If needed to perform the operation with
CGRectMake, Auto Layout needs to be disabled