我有一个scrollview
和imageview
子视图到scrollview
。按一下按钮我subview
另一个imageview
并将该图片发送到后面
[nextImageView sendSubviewToBack:firstImageView];
我希望firstImageView
淡出并在点击按钮上显示第二个图像,然后点击按钮我希望反向也发生
答案 0 :(得分:2)
好的,根据我的理解,您希望在点击按钮时“切换”几个图像。尝试以下操作,其中“img1”是第一个UIImageView,第二个UIImageView中的“img2”。这称为animation block。
-(IBAction)showSecondImg:(id)sender {
// Some code to add Img2 subview behind Img1..
[UIImageView animateWithDuration:1 // <-- Number of seconds
animations:^{
img1.alpha = 0; // <-- fade out in 1 second and shows Img2 below it
//add other animations here, like background color, etc. if needed.
}
];
}
-(IBAction)showFirstImg:(id)sender {
// gradually fades the first UIImageView back on top
[UIImageView animateWithDuration:1
animations:^{
img1.alpha = 1;
}
];
}
答案 1 :(得分:0)
调整@ jhilgert00的答案.....
-(IBAction)toggleImage:(id)sender {
if (img1.alpha==1)
{
[UIImageView animateWithDuration:1 // <-- Number of seconds
animations:^{
img1.alpha = 0;
img2.alpha = 1;
}];
}
else
{
[UIImageView animateWithDuration:1 // <-- Number of seconds
animations:^{
img1.alpha = 1;
img2.alpha = 0;
}];
}
}