如何在改变UIImageView时制作动画
我编写了这段代码并制作了 2 个按钮(下一个和后退),以使用 UIImageView 在 NSMutubleArray 中显示图片。
-(IBAction) pictureNext:(id)sender;
{
if (pictureIndice==[promMUAraay count])
{
pictureIndice=0;
}
NSLog(@"indice : %d ",pictureIndice);
Promotion *prom = [[Promotion alloc]init];
prom =[promMUAraay objectAtIndex:pictureIndice];
promotionPicture.image = [UIImage imageWithData:prom.pPicture];
//promLabel.text=prom.pName;
NSLog(@"label : %@",prom.pName);
pictureIndice++;
}
-(IBAction) pictureBack:(id)sender;
{
if (pictureIndice==[promMUAraay count])
{
pictureIndice=0;
}
NSLog(@"indice : %d ",pictureIndice);
Promotion *prom = [[Promotion alloc]init];
prom =[promMUAraay objectAtIndex:pictureIndice];
promotionPicture.image = [UIImage imageWithData:prom.pPicture];
//promLabel.text=prom.pName;
if (pictureIndice==0)
{
pictureIndice=[promMUAraay count];
}
pictureIndice--;
}
这可行,但是可以在更改图像时制作一些动画吗?
I wrote this code and made 2 buttons, next and back, to display a picture in an NSMutubleArray using an UIImageView.
-(IBAction) pictureNext:(id)sender;
{
if (pictureIndice==[promMUAraay count])
{
pictureIndice=0;
}
NSLog(@"indice : %d ",pictureIndice);
Promotion *prom = [[Promotion alloc]init];
prom =[promMUAraay objectAtIndex:pictureIndice];
promotionPicture.image = [UIImage imageWithData:prom.pPicture];
//promLabel.text=prom.pName;
NSLog(@"label : %@",prom.pName);
pictureIndice++;
}
-(IBAction) pictureBack:(id)sender;
{
if (pictureIndice==[promMUAraay count])
{
pictureIndice=0;
}
NSLog(@"indice : %d ",pictureIndice);
Promotion *prom = [[Promotion alloc]init];
prom =[promMUAraay objectAtIndex:pictureIndice];
promotionPicture.image = [UIImage imageWithData:prom.pPicture];
//promLabel.text=prom.pName;
if (pictureIndice==0)
{
pictureIndice=[promMUAraay count];
}
pictureIndice--;
}
This works, but is it possible to make a little animation when changing image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多动画选项可供选择。由于您有一个
UIImageView
对象,因此这里是一个“淡出/淡入”示例(警告:未测试):然后在您的
pictureNext
和pictureBack 您可以将 line: 更改
为以下 3 行:
旁注:
您可以通过让两个按钮调用相同的选择器并确定您的
sender
是后退还是前进按钮。There are a lot of animation options to choose from. Since you have a single
UIImageView
object, here is a "fade out/in" example (warning: not tested):Then in your
pictureNext
andpictureBack
you can change the line:to these 3 lines:
Side note:
You could combine your
pictureNext
andpictureBack
by having both buttons call the same selector and determining if yousender
is the back or forward button.