Inactive part of the screen on fullscreen - ios

I'm trying to put a picture on fullscreen with buttons on to do actions.
Here is a screenshot of my result:
My problem is that the buttons on the first line (the highest) are not touchable.
It seems to have no action on the top layout.
Here is my code:
- (void)showActionsForGlobalFullScreen:(UIGestureRecognizer *)gestureRecognizer {
//LEFT
UIImage* cancelImage = [UIImage imageNamed:#"cancel.png"];
CGRect frameimg = CGRectMake(3, 3, cancelImage.size.width, cancelImage.size.height);
UIButton *cancelButton = [[UIButton alloc] initWithFrame:frameimg];
UIImage* flagImage = [UIImage imageNamed:#"flag.png"];
CGRect frameimg2 = CGRectMake(3, 40, flagImage.size.width, flagImage.size.height);
UIButton *flagButton = [[UIButton alloc] initWithFrame:frameimg2];
[cancelButton addTarget:self action:#selector(closeFullView:) forControlEvents:UIControlEventAllTouchEvents];
[cancelButton setBackgroundImage:cancelImage forState:UIControlStateNormal];
[flagButton addTarget:self action:#selector(displayFlag:) forControlEvents:UIControlEventAllTouchEvents];
[flagButton setBackgroundImage:flagImage forState:UIControlStateNormal];
//RIGHT
UIImage *exitFullScreenImage = [UIImage imageNamed:#"exitFullScreen.png"];
CGRect frameimg3 = CGRectMake(fullScreenViewFromVC.frame.size.width - 25 , 3, exitFullScreenImage.size.width, exitFullScreenImage.size.height);
UIButton *exitFullScreenButton = [[UIButton alloc] initWithFrame:frameimg3];
UIImage *commentImage = [UIImage imageNamed:#"comment.png"];
CGRect frameimg4 = CGRectMake(fullScreenViewFromVC.frame.size.width - 25 , 40, commentImage.size.width, commentImage.size.height);
UIButton *commentButton = [[UIButton alloc] initWithFrame:frameimg4];
[exitFullScreenButton addTarget:self action:#selector(exitFullScreenPhoto:) forControlEvents:UIControlEventAllTouchEvents];
[exitFullScreenButton setBackgroundImage:exitFullScreenImage forState:UIControlStateNormal];
[commentButton addTarget:self action:#selector(diplayComments:) forControlEvents:UIControlEventAllTouchEvents];
[commentButton setBackgroundImage:commentImage forState:UIControlStateNormal];
//[actionsView addSubview:flagButton];
[fullScreenViewFromVC addSubview:cancelButton];
[fullScreenViewFromVC addSubview:flagButton];
[fullScreenViewFromVC addSubview:exitFullScreenButton];
[fullScreenViewFromVC addSubview:commentButton];
}
Important note:
fullScreenViewFromVC is an own class extending UIView and instantiated on my controller.
Basically I'm called the fullscreen method from a picture on a UITableViewCell
I'm using this fullScreenViewFromVC variable to store my data from the current selected cell to my controller.
Thank you for your help.

Finally it was because of another view that I had to hide.
I thought that changing de zPosition of my view in fullscreen should be enough but it did not.
Problem solved.

Related

UINavigationItems Stretching in iOS11

I'm updating an app to ensure that it works as expected in iOS11. The only issue I've run into is that the navigation bar looks quite different in iOS11. The position of the elements and size is not the same between versions. I've looked at my code and i'm explicitly setting frame sizes and edge insets, why are these values are not respected in iOS11?
//-- Create Right Navigation Item Buttons
// create kabob btn
UIButton *kabobBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[kabobBtn addTarget:self action:#selector(viewUsersClicked:)forControlEvents:UIControlEventTouchUpInside];
kabobBtn.clipsToBounds = YES;
[kabobBtn setImage:[UIImage imageNamed:#"KabobMenu2_0071bc_Right.png"]
forState:UIControlStateNormal];
[kabobBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
[kabobBtn setFrame:CGRectMake(0, 0, 32, 32)];
// create user profile button
UIButton *userBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[userBtn setImage:[UIImage imageNamed:#"people.png"]
forState:UIControlStateNormal];
[userBtn addTarget:self action:#selector(viewUserProfileClicked:)forControlEvents:UIControlEventTouchUpInside];
[userBtn setFrame:CGRectMake(0, 0, 38, 38)];
userBtn.clipsToBounds = YES;
[userBtn.layer setCornerRadius:(38/2)];
[userBtn.layer setMasksToBounds:YES];
[userBtn.layer setBorderColor:[[UIColor blackColor]CGColor]];
[userBtn.layer setBorderWidth:1];
self.userPictureURL = [defaults objectForKey:#"userPicture"];
[userBtn setImage:[UIImage imageNamed:#"defaultUserImage.png"] forState:UIControlStateNormal];
[userBtn setContentMode:UIViewContentModeScaleAspectFill];
[userBtn setBackgroundColor:[UIColor clearColor]];
// add buttons to bar button items
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:kabobBtn];
UIBarButtonItem *barButton2 = [[UIBarButtonItem alloc] initWithCustomView:userBtn];
// add bar button items to right bar button item array
self.navigationItem.rightBarButtonItems = #[barButton,barButton2];
//-- Create Left Hamburger Button
UIButton *customOpen = [UIButton buttonWithType:UIButtonTypeCustom];
[customOpen setFrame:CGRectMake(0, 0, 30, 44)];
[customOpen setImage:[UIImage imageNamed:#"hamburger.png"] forState:UIControlStateNormal];
[customOpen setImageEdgeInsets:UIEdgeInsetsMake(10, -5, 16, 10)];
UIBarButtonItem *openItem = [[UIBarButtonItem alloc] initWithCustomView:customOpen];
if(self.showHamburger){
self.navigationItem.leftBarButtonItem = openItem;
}else{
self.navigationItem.leftBarButtonItem = nil;
}
Apparently iOS 11 uses autolayout for nav bar buttons. Use auto layout constraints to set button width and height.
[userBtn.widthAnchor constraintEqualToConstant:38.f].active = YES;
[userBtn.heightAnchor constraintEqualToConstant:38.f].active = YES;
This should fix the stretching issue.
Thanks to this answer

How to identify the subviews (imageviews) addeded to the UIButton in UIAutomation?

I have a UIButton and the button background is set to an image. Added
an image view on the top right corner of the button and I set it
to different image when the button is clicked to show the selection.
When I try to automate this using instruments. I don’t see any subviews
(image views) in the UIAutomator.logElementTree()method does not show
any image views.
How to identify the image views added as subview in the UIButton?
Here is the code.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(40, 40, 100, 100);
[button addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[UIImage imageNamed:#“testImage.png”] forState:UIControlStateNormal];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
imageview.frame = CGRectMake(70,30,20,20);
[button addSubview:imageview];
You have to set the accessibilityEnabled & accessibilityLabel.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(40, 40, 100, 100);
[button addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
button.accessibilityEnabled = YES;
button.accessibilityLabel =#"My Button";
[button setBackgroundImage:[UIImage imageNamed:#“testImage.png”] forState:UIControlStateNormal];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
imageview.accessibilityEnabled = YES;
imageview.accessibilityLabel = #"My Image";
imageview.frame = CGRectMake(70,30,20,20);
[button addSubview:imageview];
Refer this tutorial
Sweet Angel's answer is enough if you have a single UIImageView subview. However, I would suggest using tags to identify subviews.
imageView.tag = 1346;//Any arbitrary number (I am unsure if there are any limitations to the values you can use, but all 4 digit numbers work fine for me).
Then to get the imageView:
UIImageView* imageView = (UIImageView*)[button viewWithTag:1346];
That's it.
If you want to identify imageview on button taped, try following code :
- (IBAction)didTapButton:(UIButton *)sender
{
for (id view in sender.subviews)
{
if ([view isKindOfClass:[UIImageView class]])
{
NSLog(#"Image view captured.....");
}
}
}

Custom UIBarButtonItem keep Aspect Ratio for Image but Space out Buttons

I am adding some custom image UIBarButtonItems to my navigation bar. If I do not mess with the item.width property, then my buttons are too close together, but if I space them out with the width property, then the button image is distorted. How can I maintain the aspect ratio of the button image but space out my custom items?
// Create custom map button
UIButton *mapButton = [UIButton buttonWithType:UIButtonTypeCustom];
[mapButton setImage:[UIImage imageNamed:#"map.png"] forState:UIControlStateNormal];
[mapButton addTarget:self action:#selector(dismissMapView:) forControlEvents:UIControlEventTouchUpInside];
[mapButton setFrame:CGRectMake(280, 25, 30, 30)];
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithCustomView:mapButton];
button1.width = (self.drawer.frame.size.width / 5.0f); // Space it out a bit
// Create custom list button
UIButton *listButton = [UIButton buttonWithType:UIButtonTypeCustom];
[listButton setImage:[UIImage imageNamed:#"list.png"] forState:UIControlStateNormal];
[listButton addTarget:self action:#selector(scrollToRow:) forControlEvents:UIControlEventTouchUpInside];
[listButton setFrame:CGRectMake(280, 25, 30, 30)];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:listButton];
button2.width = (self.drawer.frame.size.width / 5.0f); // Space it out a bit
// Add buttons to drawer
self.drawer.items = #[button1,button2];
Try this code for adding custom bar button in navigationbar.
UIImage* image3 = [UIImage imageNamed:#"compose_message_button.png"];
CGRect frameimg = CGRectMake(250, 9, 43,32);
UIButton *SettingButton = [[UIButton alloc] initWithFrame:frameimg];
[SettingButton setBackgroundImage:image3 forState:UIControlStateNormal];
[SettingButton addTarget:self action:#selector(BtnWriteMessage:)
forControlEvents:UIControlEventTouchUpInside];
[SettingButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:SettingButton];
self.navigationItem.rightBarButtonItem=mailbutton;
[SettingButton release];
i hope this code is useful for you.
You can create some explicit spacer items using UIBarButtonSystemItemFixedSpace.
Or you could create your bar buttons with custom views (initWithCustomView:) and then you can lay the content views out as you like.

Getting white flash animation effect upon clicking play and pause buttons

I have a single button toggling between play and pause for audio playback. When I was using the standard play/pause buttons (e.g., initWithBarButtonSystemItem:UIBarButtonSystemItemPlay), I got a nice white flash animation effect over the buttons as they toggled back and forth. But now that I am using custom images, I no longer get that effect. How can I get it back?
Also would very much appreciate any tips to simplify this as it seems heavyweight. I saw https://stackoverflow.com/a/9104587/1462372 but am not clear whether that is applicable in this case (in button bar).
Here is the code:
- (void) setAsPlaying:(BOOL)isPlaying
{
self.rootViewController.playing = isPlaying;
// we need to change which of play/pause buttons are showing, if the one to
// reverse current action isn't showing
if ((isPlaying && !self.pauseButton) || (!isPlaying && !self.playButton))
{
UIBarButtonItem *buttonToRemove = nil;
UIBarButtonItem *buttonToAdd = nil;
if (isPlaying)
{
buttonToRemove = self.playButton;
self.playButton = nil;
UIImage *pauseButtonImage = [UIImage imageNamed:#"icon_pause.png"];
UIButton *pauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[pauseButton addTarget:self action:#selector(pauseAudio:) forControlEvents:UIControlEventTouchUpInside];
pauseButton.bounds = CGRectMake(0, 0, pauseButtonImage.size.width, pauseButtonImage.size.height);
[pauseButton setImage:pauseButtonImage forState:UIControlStateNormal];
self.pauseButton = [[UIBarButtonItem alloc] initWithCustomView:pauseButton];
buttonToAdd = self.pauseButton;
}
else
{
buttonToRemove = self.pauseButton;
self.pauseButton = nil;
// this was the way I was doing it before:
// self.playButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:#selector(playAudio:)];
UIImage *playButtonImage = [UIImage imageNamed:#"icon_play.png"];
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton addTarget:self action:#selector(playAudio:) forControlEvents:UIControlEventTouchUpInside];
playButton.bounds = CGRectMake(0, 0, playButtonImage.size.width, playButtonImage.size.height);
[playButton setImage:playButtonImage forState:UIControlStateNormal];
self.playButton = [[UIBarButtonItem alloc] initWithCustomView:playButton];
buttonToAdd = self.playButton;
}
// Get the reference to the current toolbar buttons
NSMutableArray *toolbarButtons = [[self.toolbar items] mutableCopy];
// Remove a button from the toolbar and add the other one
if (buttonToRemove)
[toolbarButtons removeObject:buttonToRemove];
if (![toolbarButtons containsObject:buttonToAdd])
[toolbarButtons insertObject:buttonToAdd atIndex:5];
[self.toolbar setItems:toolbarButtons];
}
}
Try this code might be helpful to you...
UIImage* image = [UIImage imageNamed:#"facebook.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height-10);
UIButton *rightbtnItem = [[UIButton alloc] initWithFrame:frame];
[rightbtnItem setBackgroundImage:image forState:UIControlStateNormal];
[rightbtnItem setShowsTouchWhenHighlighted:YES];
Copy and paste it in your viewDidload and see glow effect on touch.
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"ar.png"] forState:UIControlStateNormal];
[button setFrame:CGRectMake(0, 0, 30, 30)];
button.center=self.view.center;
[button setBackgroundImage:[UIImage imageNamed:#"RS2kQ.png"] forState:UIControlStateHighlighted];
Get Image from here ar.png and RS2kQ.png

Assigning UIButton to UIView in Xcode

In my project i used the below code for a purpose and it is working properly.
My code:
UIView *view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",index]]] autorelease];
view.frame = CGRectMake(70, 80, 180, 260);
return view;
But here instead of UIImageView i would like to use UIButton,So I replaced the first lin eof above code by:
UIView *view=[[UIButton alloc] setBackgroundImage:(UIImage *)[scrollImages objectAtIndex:index] forState:UIControlStateNormal];
But at this point i am getting an error message as
"Initializing 'UIView*_strong' with an expression of incompatible type 'void'".
Can anyone help me to solve this by replacing UIImageView with UIButton....
You should init the instance of UIButton after created it via `alloc'
UIButton *button = [[UIButton alloc] init];
[button setBackgroundImage:(UIImage *)[scrollImages objectAtIndex:index] forState:UIControlStateNormal];
UIView *view = button;
You must use an init... method to complete the initialization process
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state return nothing (void), it's certainly incompatible type with UIView.
Like this...
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:#selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",index]];
[button setImage:image forState:UIControlStateNormal];
button.frame = CGRectMake(70, 80, 180, 260);
[self.view addSubview:button];

Resources