Reputation: 4716
I have a UIImageView full screen, there are buttons above. These buttons, when pressed should open up a larger image that has buttons. A button to open a site and the other to close the image. I thought about using a layer to bring out the image, but nothing comes out, even if the button works.
- (void)viewDidLoad
{
[super viewDidLoad];
self.bigImageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SBS_visual_ok.jpg"]];
self.bigImageView.frame = self.view.bounds;
//....
self.buttonInternational =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.buttonInternational addTarget:self action:@selector(pressedInternational:) forControlEvents:UIControlEventTouchUpInside];
self.buttonInternational.frame = CGRectMake (100, 100, 100, 100);
//...
[self.view addSubview:self.bigImageView];
[self.bigImageView addSubview:self.buttonInternational];
}
pressing the button I want to get a picture with some buttons, but does not come out even the image. I have imported
-(void)pressedInternational:(id)sender{
CALayer *layer =[CALayer layer];
layer.frame = CGRectMake(300, 400, 300, 200);
layer.contents =(id)[UIImage imageNamed:@"International_Security_Service.png"].CGImage;
[[self.bigImageView layer]addSublayer:layer];
NSLog(@"The layer is %@", layer);
//The layer is <CALayer: 0x757ba30>
}
How do I put on a layer of buttons?
Upvotes: 0
Views: 362
Reputation: 4286
Why are you trying to use a CALayer? It would probably be easier to display another UIView, which can have images, buttons, whatever:
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(10.0, 10.0, 300.0, 300.0)];
[self.view addSubview:myView];
which you can easily show / hide
[self.myView setHidden:YES];
or push a new view controller:
MyViewController *nextViewController = [[MyViewController alloc] init];
[self presentViewController:myViewController animated:YES completion:nil];
If necessary, you could apply animations to the display and removal of either of these.
Upvotes: 1