Adding Gesture Recognizer for panning a UIView - iphone

After seeing some examples, I'm trying to create a window where an Image view could be moved with the PanGestureRecognizer. I don't understand what is missing.
I created and initialized an UIView object
I also created an UIGestureRecognizer for panning, for both views.
I created the method to be selected when Gesture is recognized.
If you have an idea of what is missing, I would be thankful to read it;
Here is my code:
View Controller.h
#import <UIKit/UIKit.h>
#import "bouton.h"
#interface ATSViewController : UIViewController {
boutonHome *bouton; }
#property (retain, nonatomic) boutonHome *bouton;
-(IBAction)handlePanGesture:(UIPanGestureRecognizer*)sender;
#end
View Controller.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:#"back.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
// Set self's frame to encompass the image
bouton.frame = frame;
bouton.boutonImage = image;
[self.view addSubview:bouton];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanGesture:)];
[bouton setUserInteractionEnabled:YES];
[bouton addGestureRecognizer:panGesture];
[self.view setUserInteractionEnabled:YES];
[self.view addGestureRecognizer:panGesture];
// Do any additional setup after loading the view, typically from a nib.
}
-(IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender
{
CGPoint translate = [sender translationInView:self.view];
CGRect newFrame = bouton.frame;
newFrame.origin.x += translate.x;
newFrame.origin.y += translate.y;
sender.view.frame = newFrame;
if(sender.state == UIGestureRecognizerStateEnded)
bouton.frame = newFrame;
}
BoutonHome.h
#import <Foundation/Foundation.h>
#interface boutonHome : UIView
{
UIImage *boutonImage;
}
#property (nonatomic, retain) UIImage *boutonImage;
// Initializer for this object
#end
boutonHome.m
#import "bouton.h"
#implementation boutonHome
#synthesize boutonImage;
#end

Related

UIButton outside of UIView (xib) frame

I have a custom UIView XIB that gets loaded onto my ViewController and the frame is adjusted to be collapsed before added to subview. The UIButton tied to my XIB is showing when the frame is smaller than the button location. How can I hide and show my UIButton as the frame is expanding/collapsing? My XIB is not using AutoLayout.
ViewController.m
self.greenView = [[[NSBundle mainBundle] loadNibNamed:#"Green" owner:self options:nil] objectAtIndex:0];
[self.navigationController.view addSubview:self.greenView];
GreenView.h
#interface GreenView : UIView
#property (weak, nonatomic) IBOutlet UIView *expandView;
#property (nonatomic, getter = isExpanded) BOOL expand;
#property (weak, nonatomic) IBOutlet UIButton *testButton;
- (IBAction)testButtonTapped:(id)sender;
#end
GreenView.m
#interface GreenView()
#property (nonatomic) UITapGestureRecognizer *tapGesture;
#end
#implementation GreenView
- (void)awakeFromNib {
CGRect frame = self.frame;
frame.size.height = self.expandView.frame.size.height;
frame.origin.y = 200;
self.frame = frame;
self.expand = NO;
[self.expandView addGestureRecognizer:self.tapGesture];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (UITapGestureRecognizer *)tapGesture {
if (!_tapGesture) {
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapClicked:)];
}
return _tapGesture;
}
- (void)tapClicked:(UIGestureRecognizer *)recognizer {
CGRect frame = self.frame;
self.expand = !self.expand;
frame.size.height = self.expand ? gvExpandedHeight : gvCollapsedHeight;
[UIView animateWithDuration:0.5 animations:^{
self.frame = frame;
} completion:^(BOOL finished) {
NSLog(#"Frame after animation: %#", NSStringFromCGRect(self.frame));
}];
}
- (IBAction)testButtonTapped:(id)sender {
NSLog(#"Test button tapped");
}
#end
Collapsed:
Expanded:
GreenView.xib:
GrenenView.xib Struts and Springs:
If I understood you just want to clip it, if the button is outside to the view bounds. In -awakeFromNib add:
self.clipsToBounds = YES;
Using this property you are telling the view to cut everything that is not inside its bounds, views caw draw subviews even if they are place outside. Is a little expensive by means of performance, if you use it a lot or during heavy animations.
One way around could be hide it while the view is collapsed.
You change the frame to frame.origin.y = 200;
I think you have to set the UIButton constraint relative to your GreenView in you nib file

touchesBegan not functioning on programmatically created view and imageview

I am programmatically creating a view and a imageview while in viewControllerA for an another viewControllerB before I then goto viewControllerB. I have to do this, as I am using an image from the imagePickerController. However by doing this, touchesBegan does not function in viewControllerB
I have set UserInteractionEnabled to true/yes in both the attributes inspector of the xib and programmatically everywhere!
My xib is just a blank canvas, with one View. I have tried different settings with the connections inspector, but still no luck.
Here is my code.
viewControllerA.m
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
view = [[UIView alloc] initWithFrame:screenRect];
image = [info valueForKey:UIImagePickerControllerEditedImage];
SSViewController *psView = [[SSViewController alloc] initWithNibName:#"SSViewController" bundle:nil];
psView.view = [[UIView alloc] initWithFrame:screenRect];
[psView.view setUserInteractionEnabled:YES];
[picker pushViewController:psView animated:YES];
imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(20, 20, 280, 280);
[imageView setUserInteractionEnabled:YES];
[psView.imageView setUserInteractionEnabled:YES];
[psView.view addSubview:imageView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:psView action:#selector(endPS:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"done" forState:UIControlStateNormal];
button.frame = CGRectMake(140.0, 330.0, 80.0, 25.0);
[psView.view addSubview:button];
}
viewControllerB.h (SSViewController.h)
#interface SSViewController : UIViewController
{
IBOutlet UIImageView *imageView;
IBOutlet UIView *view;
}
#property (nonatomic,strong) IBOutlet UIImageView *imageView;
#property (nonatomic,strong) IBOutlet UIImage *image;
#property (nonatomic, strong) IBOutlet UIView *view;
- (IBAction)endPS:(id)sender;
#end
viewControllerB.m (SSViewController.m)
#implementation SSViewController
#synthesize imageView;
#synthesize image;
#synthesize view;
:
:
- (void)viewDidLoad
{
[view setUserInteractionEnabled:YES];
[imageView setUserInteractionEnabled:YES];
:
:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"touchesBegan");
:
You're doing a number of things wrong:
Don't push a view controller on to the UIImagePickerController. If you've presented it modally, which I hope you have, you need to dismiss it (in viewControllerA) and push your new view controller (viewControllerB) onto your own navigation controller. The fact that you're pushing onto this highly customised navigation controller is most likely why touchesBegan is not being called.
Why are you manually creating the view for viewControllerB? If you're loading it from a XIB file, it will have a perfectly good view ready for you. And don't define the view property in viewControllerB.h, it's already defined in UIViewController.h.
Don't forget to call [super viewDidLoad] in viewControllerB.m. This is a classic mistake that will cause you many headaches.
EDIT:
What I would personally have done is added a method on viewControllerB as such:
viewControllerB.h
#interface SSViewController : UIViewController
{
- (void)setImage:(UIImage *)image;
}
#end
viewControllerB.m
#implementation SSViewController
{
- (void)setImage:(UIImage *)image
{
// In case the image view already exists, remove it first.
[_imageView removeFromSuperview];
_imageView = [[UIImageView alloc] initWithImage:image];
_imageView.frame = CGRectMake(20, 20, 280, 280);
[self.view addSubview:_imageView];
}
}
#end
This way, in viewControllerA.m you can just create viewControllerB.m and call this setImage: method to let viewControllerB do all the work.

Xcode Error Semantic error value may not respond to 'initWithFrame:image Name:'

I am getting an error in my project. I have tried plenty of solutions but to no avail.
I am getting an error Xcode Error Semantic error value may not respond to 'initWithFrame:image Name:'
I have no idea what this means and why i'm getting this warning. Please help.
Thanks
Link to my project and the Updated project link.
I'm getting the error in this line
GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height) imageName:imgName];
GalleryScrollView.h
#import <UIKit/UIKit.h>
#import "AttachmentItem.h"
#import "GalleryButton.h"
#protocol GAlleryScrollDelegate;
#interface GalleryScrollView : UIView <GalleryButtonDelegate>
{
id <GAlleryScrollDelegate> delegate;
// MAIN WINDOW WHERE YOU CAN DRAG ICONS
UIView *mainView;
UIScrollView *_scrollView;
NSMutableArray *_attachments;
NSInteger *_totalSize;
UIImageView *_recycleBin;
CGRect recycleBinFrame;
}
#property (nonatomic, retain) id <GAlleryScrollDelegate> delegate;
#property (nonatomic, retain) UIView *mainView;
#property (nonatomic, retain) NSMutableArray *attachments;
#property (nonatomic, retain) UIImageView *recycleBin;
#property (nonatomic, retain) UIImageView *imgName;
#property (nonatomic) CGRect recycleBinFrame;
- (void) addAttachment:(AttachmentItem *)attachment withImageNamed:(NSString *)imgName;
- (void) removeAttachment:(GalleryButton *)button;
- (void) reloadData;
- (id) initWithFrame:(CGRect)frame imageName:(NSString *)imageName;
#end
// EVENTS IF YOU WANT TO DISABLE SOME SCROLL ON DID PRESS AND ENABLE IT ON DROP
#protocol GAlleryScrollDelegate
- (void) didPressButton;
- (void) didDropButton;
#end
GalleryScrollView.m
#import <QuartzCore/QuartzCore.h>
#import "GalleryScrollView.h"
#import "GalleryButton.h"
#implementation GalleryScrollView
#synthesize delegate;
#synthesize mainView;
#synthesize attachments = _attachments;
#synthesize recycleBin = _recycleBin, recycleBinFrame;
int padding = 0;
#pragma mark - INIT
- (id) init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (id) initWithFrame:(CGRect)frame imageName:(NSString *)imageName
{
self = [super initWithFrame:frame];
if (self){
;
}
return self;
}
- (void) awakeFromNib
{
// INIT ATTACHMENT ARRAY
if (_attachments == nil){
_attachments = [[NSMutableArray alloc] init];
}
// SCROLL VIEW
UIScrollView *scrollTemp = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-0, 450)];
_scrollView = scrollTemp;
_scrollView.backgroundColor = [UIColor clearColor];
// RECYCLE BIN
UIImageView *imageViewTemp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"mozambique-wenge.png"]];
self.recycleBin = imageViewTemp;
self.recycleBin.frame = CGRectMake(0, 0, 320, 270);
[self addSubview:_scrollView];
[self addSubview:self.recycleBin];
[scrollTemp release];
[imageViewTemp release];
}
- (void) dealloc {
[super dealloc];
}
#pragma mark - ATTACHMENTS ADD / REMOVE
- (void) addAttachment:(AttachmentItem *)attachment withImageNamed:(NSString *)imgName
{
// SAVE ATTACHMENT
[_attachments addObject:attachment];
// RESIZE CONTENT VIEW FOR INSERTINT NEW ATTACHMENT
_scrollView.contentSize = CGSizeMake([_attachments count]*70, 70);
CGFloat startX = (70.0f * ((float)[_attachments count] - 1.0f) + padding);
CGFloat startY = 370;
CGFloat width = 64;
CGFloat height = 64;
GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height) imageName:imgName];
btnAttachment.tag = [_attachments count];
btnAttachment.scrollParent = _scrollView;
btnAttachment.mainView = self.mainView;
btnAttachment.delegate = self;
if (attachment.type == 1){
}else if (attachment.type == 2){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:#"mozambique-wenge"];
[btnAttachment addSubview:imageView];
[imageView release];
} else if (attachment.type == 3){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:#"recyclebin.png"];
[btnAttachment addSubview:imageView];
[imageView release];
}
[_scrollView addSubview:btnAttachment];
[btnAttachment release];
}
- (void) removeAttachment:(GalleryButton *)button
{
}
#pragma mark - RELOAD DATA
- (void) reloadData
{
}
#pragma mark - GALLERY BUTTON DELEGATE
-(void) touchDown
{
[self.delegate didPressButton];
}
-(void) touchUp
{
[self.delegate didDropButton];
_scrollView.scrollEnabled = YES;
}
-(BOOL) isInsideRecycleBin:(GalleryButton *)button touching:(BOOL)finished;
{
CGPoint newLoc = [self convertPoint:self.recycleBin.frame.origin toView:self.mainView];
CGRect binFrame = self.recycleBin.frame;
binFrame.origin = newLoc;
if (CGRectIntersectsRect(binFrame, button.frame) == TRUE){
if (finished){
[self removeAttachment:button];
}
return YES;
}
else {
return NO;
}
}
#end
GalleryButton.h
#import <UIKit/UIKit.h>
#protocol GalleryButtonDelegate;
#interface GalleryButton : UIView
{
id<GalleryButtonDelegate> delegate;
CGPoint _originalPosition;
CGPoint _originalOutsidePosition;
BOOL isInScrollview;
// PARENT VIEW WHERE THE VIEWS CAN BE DRAGGED
UIView *mainView;
// SCROLL VIEW WHERE YOU GONNA PUT THE THUMBNAILS
UIScrollView *scrollParent;
UIImageView *images;
}
#property (nonatomic, retain) id<GalleryButtonDelegate> delegate;
#property (nonatomic) CGPoint originalPosition;
#property (nonatomic, retain) UIView *mainView;
#property (nonatomic, retain) UIScrollView *scrollParent;
#property (nonatomic, retain) IBOutlet UIImageView *images;
#end
#protocol GalleryButtonDelegate
-(void) touchDown;
-(void) touchUp;
-(BOOL) isInsideRecycleBin:(GalleryButton *)button touching:(BOOL)finished;
#end
GalleryButton.m
#import <QuartzCore/QuartzCore.h>
#import "GalleryButton.h"
#import "GalleryScrollView.h"
#import "AttachmentItem.h"
#implementation GalleryButton
#synthesize delegate;
#synthesize originalPosition = _originalPosition;
#synthesize mainView, scrollParent;
#synthesize images;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self){
isInScrollview = YES;
self.backgroundColor = [UIColor blackColor];
self.layer.borderWidth = 2;
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 5;
}
return self;
}
#pragma mark - DRAG AND DROP
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.delegate touchDown];
self.originalPosition = self.center;
self.scrollParent.scrollEnabled = NO;
if (isInScrollview == YES) {
CGPoint newLoc = CGPointZero;
newLoc = [[self superview] convertPoint:self.center toView:self.mainView];
_originalOutsidePosition = newLoc;
// [self.superview touchesCancelled:touches withEvent:event];
[self removeFromSuperview];
self.center = newLoc;
[self.mainView addSubview:self];
[self.mainView bringSubviewToFront:self];
isInScrollview = NO;
}
else {
;
}
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView beginAnimations:#"stalk" context:nil];
[UIView setAnimationDuration:.001];
[UIView setAnimationBeginsFromCurrentState:YES];
UITouch *touch = [touches anyObject];
self.center = [touch locationInView: self.superview];
[UIView commitAnimations];
if ([delegate isInsideRecycleBin:self touching:NO]){
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([delegate isInsideRecycleBin:self touching:YES]){
CGRect myImageRect = CGRectMake(0, 0, 320, 300);
images = [[UIImageView alloc] initWithFrame:myImageRect];
[images setImage:[UIImage imageNamed:#"light-cherry.png"]];
[self.mainView addSubview:images];
[self.images viewWithTag:1];
UIImageView * animation = [[UIImageView alloc] init];
animation.frame = CGRectMake(self.center.x - 32, self.center.y - 32, 40, 40);
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed: #"iconEliminateItem1.png"],
[UIImage imageNamed: #"iconEliminateItem2.png"],
[UIImage imageNamed: #"iconEliminateItem3.png"],
[UIImage imageNamed: #"iconEliminateItem4.png"]
,nil];
[animation setAnimationRepeatCount:1];
[animation setAnimationDuration:0.35];
[animation startAnimating];
[self.mainView addSubview:animation];
[animation bringSubviewToFront:self.mainView];
[animation release];
;
[UIView beginAnimations:#"goback" context:nil];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationBeginsFromCurrentState:YES];
self.center = _originalOutsidePosition;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: #selector(animationDidStop:finished:context:)];
// loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
} else{
[UIView beginAnimations:#"goback" context:nil];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationBeginsFromCurrentState:YES];
self.center = _originalOutsidePosition;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: #selector(animationDidStop:finished:context:)];
// loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
}
[self.delegate touchUp];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString:#"goback"] && finished) {
[self removeFromSuperview];
self.center = _originalPosition;
[self.scrollParent addSubview:self];
isInScrollview = YES;
}
}
#end
The problem is that you haven't declared the custom init method:
- (id)initWithFrame:(CGRect)frame imageName:(NSString *)imageName;
In GalleryButton.h. You also haven't implemented it in GalleryButton.m. Perhaps you didn't mean to use this method at all in your code?
Either way you've referenced it and Xcode has correctly warned you that it doesn't exist (if you build and run the code you will get an Unrecognized selector sent to instance exception).
You need to place initWithFrame:image Name in GalleryButton in its header file. Always remember, if you get a warning that's says something like "May not respond to..." It's because it's not publicly mentioned in the classes header file.
Okay. After killing myself trying I found my mistake.
I Used:
- (id)initWithFrame:(CGRect)frame imageName:(NSString *)imageName;
In both the GalleryButton.h and GalleryScrollview.h and I just took it out of GalleryScrollview.h
Thanks All

Scrolling of images using UIScrollView in iphone

I am a newbie to iphone development and i am doing a simple app for practice. In that app,there is only one view that has an image on it. I want to be able to swipe left or right and have the first image go out of the view and the second image to come in. The images are different and I want it to look like they are connected. I need it to be able to change the image or restart after a series of swipes. I am doing this using ScrollView only.
I have tried something:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIScrollViewDelegate>
{
UIImageView *imgView;
UIScrollView *scrollView;
}
#property (nonatomic,retain)IBOutlet UIImageView *imgView;
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
//- (id)initWithPageNumber:(int)page;
- (IBAction)changePage:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize imgView,scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
- (id)initWithPageNumber:(int)page{
if (self = [super initWithNibName:#"MyView" bundle:nil])
{
pageNumber = page;
}
return self;
}
*/
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollview
{
scrollView.contentOffset = CGPointMake(scrollview.bounds.size.width, 0);
}
- (IBAction)changePage:(id)sender
{
NSArray *images = [[NSArray alloc] initWithObjects:#"1.jpeg",#"2.jpeg",#"3.jpeg", nil];
scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];
CGRect cRect = scrollView.bounds;
for (int i = 0; i < images.count; i++){
imgView = [images objectAtIndex:i];
imgView.frame = cRect;
[scrollView addSubview:imgView];
cRect.origin.x += cRect.size.width;
}
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * images.count, scrollView.bounds.size.height);
scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0);
}
#end
When i run the app, I am still not able to swipe across the images. Am i doing something wrong? Need some guidance on this. Thanks..
This error indicates that you have a connection in Interface Builder with an IBOutlet that does not exist in your view controller class.
Make sure your IBOutlets are named correctly and that you have removed all obsolete connections in IB.
scrollView.ContentSize = (scrollView.frame.size.width * images.count
,scrollView.frame.size.height)
do this after lopping it will swipe

Is it possible to animate the width of a UIButton of UIButtonStyleCustom type?

I have an animation on frame size which works fine when the UIButton is a UIButtonTypeRoundedRect. But has no visible affect when I am using a UIButtonStyleCustom with background image. My animation code is here:
[UIView beginAnimations:#"MyAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.25];
CGRect tempFrame = myButton.frame;
tempFrame.size.width = tempFrame.size.width + 100.0f;
myButton.frame = tempFrame;
[UIView commitAnimations];
Thanks for the help!
I've tried your example in my XCode. All works fine with both buttons. So some additional questions... Do you use Background or Image? What is view's mode (Scale to Fill or something else)? And where do you test your app (device or simulator, iphone 3 or iphone 4 or ...)?
Also make some checks. Check that myButton is connected in IB (maybe, you've created a new button and forgot to do this). Check that this code runs (maybe, you forgot connection to necessary touch action).
Hey guys, I finally resolve my problem. I subclassed UIView and added two UIImageViews and an UIButton to it. The animation is perfectly good now!
Here is the code:
.h
#import <UIKit/UIKit.h>
#interface NNAnimatableButton : UIView {
UIImageView *backgroundImageView;
UIImageView *imageView;
UIButton *button;
}
#property (nonatomic, retain) UIImageView *backgroundImageView;
#property (nonatomic, retain) UIImageView *imageView;
#property (nonatomic, retain) UIButton *button;
#end
.m
#import "NNAnimatableButton.h"
#implementation NNAnimatableButton
#synthesize backgroundImageView, imageView, button;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CGRect rect = CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height);
NSUInteger autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
// Initialization code.
backgroundImageView = [[UIImageView alloc] initWithFrame:rect];
backgroundImageView.autoresizingMask = autoresizingMask;
imageView = [[UIImageView alloc] initWithFrame:rect];
imageView.autoresizingMask = autoresizingMask;
imageView.contentMode = UIViewContentModeCenter;
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.autoresizingMask = autoresizingMask;
[button setFrame:rect];
[self addSubview:backgroundImageView];
[self addSubview:imageView];
[self addSubview:button];
[backgroundImageView release];
[imageView release];
}
return self;
}
- (void)dealloc {
[backgroundImageView release];
[imageView release];
[button release];
[super dealloc];
}
#end