ios - 如何根据不同的形状拼贴图像

标签 ios iphone objective-c

<分区>

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

我试过这些链接 How to make a view resize on swipe within a photo collage for iOS?

enter image description here

最佳答案

我只是说说我的逻辑。

  • 您的 View 已显示 4 张图像(具有不同的形状) 因此您需要在 .h 文件中获取 4 个 UIImageView 和一个 UIView name is ImgContainerView in .h file
  • 确保您的所有按钮都具有相同的操作方法并将所有按钮赋予它的标签。例如每个按钮的方法名称是

    -(void) buttonMethodName:(UIButton *) sender

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

    -(void)setUpimagesByselectedButton:(int) buttonTag

在按钮的action方法中调用该方法,例如

-(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 都会重新创建它的特定形状。

关于ios - 如何根据不同的形状拼贴图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619968/

相关文章:

iphone - 使用 Go 为 iPhone 应用程序编写库

ios - 将 subview 添加到 UITabBarController 不调用 viewWillAppear

IOS Segue 无法直接设置标签

iphone - 如何让 UITextField 响应 UITextFieldDelegate?

ios - 不为某些设备生成设备 token ?

iphone - 按下选项卡栏上的项目时如何运行代码?

iphone - 如何识别在 Objective-C 中单击了哪个按钮?

ios - 只需在 cellforrow 中进行一次查询即可在 tableview 中快速实现相当大的跳跃

iphone - 完全用代码复制 PhotoScroller

ios - 外部附件流在 100% 的时间都不起作用