I’d like to have a view (UIView) with two UIImageView subviews,
and then move the two images (simultaneously) around the screen.
In scenario 1, I create a UIView with the dimensions of the screen, and leave it fixed,
and then move the center point of the two subviews around. In scenario 2, I create
a UIView the size of the two images, and move the UIView centre point around the screen.
I would have thought the end result would be the same, but it’s not.
Why not?
scenario 1:
UIView mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIImageView firstImage = [[UIImageView alloc] initWithFrame:muchSmallerRect];
UIImageView secondImage = [[UIImageView alloc] initWithFrame:muchSmallerRect];
[mainView addSubview:firstImage];
[mainView addSubview:secondImage];
firstImage.center = someSpecificPoint;
secondImage.center = someSpecificPoint;
scenario 2:
UIView mainView = [[UIView alloc] initWithFrame:muchSmallerRect];
UIImageView firstImage = [[UIImageView alloc] initWithFrame:muchSmallerRect];
UIImageView secondImage = [[UIImageView alloc] initWithFrame:muchSmallerRect];
[mainView addSubview:firstImage];
[mainView addSubview:secondImage];
mainView.center = someSpecificPoint;
You’re talking about two different coordinate systems.
mainView.centeris expressed in the coordinate system of the view that containsmainView, whereasfirstView.centerandsecondView.centerare in terms of the coordinate system ofmainView. You can certainly movefirstViewandsecondViewtogether by moving the view that contains them, but you need to translate between those two coordinate systems if you want to get the same result that you get by moving the two views themselves.