【问题标题】:Moving multiple images in xcode在 xcode 中移动多个图像
【发布时间】:2012-01-17 00:40:36
【问题描述】:

我想在一个 xib 中放置多个图像并单独移动它们。

但是,当我单击其中一张图片时,另一张会消失。我不想那样。

任何

【问题讨论】:

  • 您可能应该添加更多详细信息来描述您正在做什么以及您正在尝试做什么。

标签: xcode uiimage xcode4.2


【解决方案1】:

在您的视图控制器中

 #import "ImageMove.h"
- (void)viewDidLoad
{
    [super viewDidLoad];
    ImageMove* imageMove = [[ImageMove alloc] initWithImage:[UIImage imageNamed:@"11.jpg"]];

[imageMove setFrame:CGRectMake(110, 60, [imageMove frame].size.width,[imageMove frame].size.height)];

[[self view] addSubview:imageMove];

[imageMove release];

ImageMove* imageMove1 = [[ImageMove alloc] initWithImage:[UIImage imageNamed:@"feder.jpg"]];

[imageMove1 setFrame:CGRectMake(110, 200, [imageMove1 frame].size.width,[imageMove1 frame].size.height)];

[[self view] addSubview:imageMove1];

[imageMove1 release];

}

这是你的 imageView 类...

@interface ImageMove : UIImageView {

}

@end

@implementation ImageMove


  - (id) initWithImage:(UIImage *)image 
  {
if (self = [super initWithImage:image])
  {
    [self setUserInteractionEnabled:YES]; 

    [self setMultipleTouchEnabled:YES];
   } 

   return self;

   }


 - (void)dealloc 
 {

     [super dealloc];
  }

  - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {

if ([touches count] == 1)
{

  CGPoint newTouch = [[touches anyObject] locationInView:[self superview]]; 

  CGPoint lastTouch = [[touches anyObject] previousLocationInView: [self superview]];

    float xDif = newTouch.x - lastTouch.x; 

    float yDif = newTouch.y - lastTouch.y;

    CGAffineTransform translate = CGAffineTransformMakeTranslation(xDif, yDif);

    [self setTransform: CGAffineTransformConcat([self transform], translate)]; 

  } 


 }

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
 {


[self touchesEnded:touches withEvent:event];

 }




 @end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    相关资源
    最近更新 更多