如何根据不同的形状拼贴图像 [英] How to make collage of images according to different shapes

查看:367
本文介绍了如何根据不同的形状拼贴图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iPhone中制作拼贴图像。我给了图像,底部有不同的形状,根据这些形状,我想改变图像。所以请帮助我任何人。非常感谢,我将非常感谢您的努力和帮助。非常感谢.......

How to make collage of images in iPhone. I've given the image and there are different shapes in the bottom, according to these shapes i want to change the images. So please help me any one. It will be very thankful and i will really appreciate your effort and help. Thanks a lot.......

我已经尝试过这些链接
如何在iOS照片拼贴中刷卡时调整视图大小?

And i've tried these link How to make a view resize on swipe within a photo collage for iOS?

推荐答案

我只是把我的逻辑。


  • 你的视图已被显示4张图片(具有不同形状)因此您需要在 .h 文件中获取4 UIImageView 并且一个 UIView 名称 .h 文件中的 ImgContainerView

  • 确保您的所有按钮有相同的操作方法,并为其提供标记的所有按钮。例如,每个按钮的方法名称为

  • your view has been display 4 images (with different shape) so you need to take 4 UIImageView in .h file and one UIView name is ImgContainerView in .h file
  • make sure that your all button has same action method and give all button to it's tag. for example each button has method name is


- (void)buttonMethodName:(UIButton *)sender

-(void) buttonMethodName:(UIButton *) sender


  • 然后你需要创建一个方法名称,

  • Then you need to create one method name is,


    - (void)setUpimagesByselectedButton :(int)buttonTag

    -(void)setUpimagesByselectedButton:(int) buttonTag


  • 在按钮的动作方法中调用此方法,如

    Call this method in button's action method, such like

    -(void) buttonMethodName:(UIButton *) sender           
    {
      [self setUpimagesByselectedButton:sender.tag]; // pass button's tag as parameter.
    }
    

    现在方法中,

    -(void)setUpimagesByselectedButton:(int) buttonTag
    {
      // first you need to remove all subview of ImgContainerView 
      if(self.ImgContainerView)
      {
        for(UIView *subview in self.ImgContainerView.subviews)
            [subview removeFromSuperview];
        [self.ImgContainerView removeFromSuperview]; self.ImgContainerView = nil;
      }
      // Then re-create  ImgContainerView with background color is white;
      // add all UIImageView as subView of ImgContainerView;
      // and then set FRAME of your UIImageView base on selected button's tag such like.
      if(buttonTag == 1)// for ex. i take 1, here you write your button's tag.
        self.imageView1.frame....
      // create one by one imageView and set it's frame by put condition as above       
      // your UIImageView's contentMode should be  UIViewContentModeScaleAspectFill or UIViewContentModeCenter;
    }
    

    当你点击任何按钮时,每次 ImgContainerView 是用它的特殊形状重新创建的。

    When you tap any button then each time ImgContainerView is re-created with it's particular shape.

    这篇关于如何根据不同的形状拼贴图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆