Using UIImagePickerController in iPad Mini iOS 7 - ios

I have an app targeting iPhone. The UIImagePickerController works fine on iPhone, but when I open it with iPad Mini on iOS 7, the top part of UIImagePickerController was hidden, which hide the front/back camera toggle button. How can I solve this?
Update:
I observed through subview hierarchies that the "CAMFlipButton" has wrong frame:
<CAMFlipButton: 0x176e6250; baseClass = UIButton; frame = (310.5 9.5; 48 70); opaque = NO; layer = <CALayer: 0x176e63c0>>

I had the same issue; it seems to affect only the iPad Mini (but only the non-retina version), on both iOS 7 and 8. Not sure why not many people faced this issue, but I couldn't find a working solution or workaround.
So what I did (what I hacked!) is I detect when this happens (when the button ends up outside the window bounds), and correct it, by moving the button back into the window, and adding my own image to the button.
#interface MyImagePickerController : UIImagePickerController
#end
#implementation MyImagePickerController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
showFlipButtonInSubviews(self.view);
}
void showFlipButtonInSubviews(UIView *view) {
if ([[[view class] description] isEqualToString:#"CAMFlipButton"]) {
if (view.x + view.width > UIScreen.mainScreen.bounds.size.width + 5) {
// Fixes this: http://stackoverflow.com/questions/20895993/using-uiimagepickercontroller-in-ipad-mini-ios-7
// Happens on iPad Mini non-retina only
view.x = UIScreen.mainScreen.bounds.size.width - view.width - 10;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 23, 16)];
imageView.image = [UIImage imageNamed:#"switch-camera"];
[view addSubview:imageView];
}
} else {
for (UIView *subview in [view subviews]) {
showFlipButtonInSubviews(subview);
}
}
}
#end
Why UIScreen.mainScreen.bounds.size.width + 5 you ask? Simply because on the iPad Mini retina, that button has 4 pixels outside the window, but it still shows correctly, so I don't want to apply this hack then.
My switch-camera image looks like this:
(hard to see, it's white! right-click or drag it around to see it...)

Related

TabBar moving up whenever a ViewController is pushed in iPhone X

I've recently added support to iOS 11 on my app and this started happening. Basically, whenever a ViewController is added to the navigation stack the tab bar glitches out during the animation.
It only happens in iPhone X, and this is just a regular TabBarController. What's causing it?
Additional answer
A radar is open about this problem here.
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// Disable tabBar shifts upward whenever a ViewController is pushed on iPhone X rdar://35098813
BOOL isIPhoneX = ...
if (isIPhoneX && UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
[self.tabBar setFrame:CGRectMake(0, CGRectGetHeight(self.view.frame) - CGRectGetHeight(self.tabBar.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.tabBar.frame))];
}
}
Original answer
I think this is a bug of iOS 11.
You can remove that weird effect to put down this code to your subclass of UITabBarController.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
BOOL isIPhoneX = ...
if (isIPhoneX && UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
[self.tabBar setFrame:CGRectMake(0, self.view.frame.size.height - 83, 375, 83)];
}
}
The solution is weird, too. :)

iOS Facebook Like Button Not Resizing

I am setting up an iOS app and have implemented a Facebook like button. Problem is, when I try to adjust the size according to their documentation found here, it just does not resize. Here's my setup code which is all the code that uses the like button:
(ViewController.h)
#property FBSDKLikeControl* likeButton;
(ViewController.m)
#synthesize likeButton;
- (void)viewDidLoad {
...
likeButton = [[FBSDKLikeControl alloc] initWithFrame:CGRectMake(20, 20, 128, 64)];
likeButton.objectID = #"https://www.facebook.com/mypage";
}
- (void)showLikeButton {
[self.view addSubview:likeButton];
}
- (void)hideLikeButton {
[likeButton removeFromSuperview];
}
When showLikeButton is called (which is after the app has been running a little while), the button shows up as expected, but no matter what size I initialize the button with, it doesn't change its size. Any ideas? Thanks in advance.
Use FBSDKLikeButton in place of FBSDKLikeControl. It inherits from UIButton and responds to sizing changes, although the image resolution suffers.

Programmatic Device Specific iOS Constraint is nil

I came across an interesting problem that only arises on iPhone 6/6+ and iPad mini with retina display.
In the following code:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(self.seeMoreContents)
{
BOOL isText = [self.seeMoreContents isText];
self.imageView.hidden = isText;
[self.textView removeConstraint:self.textHeightConstraint];
[self.textWrapperView removeConstraint:self.textWrapperHeightConstraint];
if (!isText)
{
__weak FCSeeMoreViewController *weakSelf = self;
[self.imageView setImageByFlashcardSide:self.seeMoreContents completion:^(BOOL preloaded){
weakSelf.imageView.center = CGPointMake(weakSelf.view.frame.size.width / 2, weakSelf.view.frame.size.height / 2);
[weakSelf.scrollView setContentOffset:CGPointMake(0, 0)];
}];
}
}
}
- (void)viewDidLayoutSubviews
{
if ([self.seeMoreContents isText])
{
self.textView.text = self.seeMoreContents.text;
self.textView.font = self.fontForContents;
self.textWrapperView.hidden = NO;
[self.textView sizeToFit];
CGFloat height = self.textView.frame.size.height;
[self updateView:self.textView withConstraint:self.textHeightConstraint ofValue:height];
[self updateView:self.textWrapperView withConstraint:self.textWrapperHeightConstraint ofValue:height + self.wrapperMargin];
[self.scrollView setContentSize:CGSizeMake(self.textView.frame.size.width, height + self.scrollTextMargin)];
[self.scrollView setContentOffset:CGPointMake(0, -self.wrapperScrollVerticalConstraint.constant)];
}
[super viewDidLayoutSubviews];
}
- (void)updateView:(UIView*)view withConstraint:(NSLayoutConstraint*)constraint ofValue:(CGFloat)value
{
constraint.constant = value;
[view addConstraint:constraint];
}
By the time the two messages of udpateView get passed, the constraints have become nil. I could attribute this to weird garbage collection behavior, but it only happens on iPhone 6/6+ and mini retina iPad.
I have changed this whole controller to work better and to not to programmatically set constraints, but I want to know how/why this can happen on specific devices. Any insight would be greatly appreciated.
Override this method in your UIViewController to detect changing of 'traits':
func willTransitionToTraitCollection(_ newCollection: UITraitCollection,
withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
This is where you intercept constraint changes to get them at the right time, otherwise it's a race and your code can lose.
I suspect not using that function to get the timing right may be why you are not seeing consistent results. I bumped into the same kind of problem awhile back - not finding constraints that should have been there when I went looking for them.
Another thing to consider about mysterious constraints appearing and disappearing, of course, is UIView's
translatesAutoresizingMaskIntoConstraints
property, which if true (the default), causes iOS to dynamically create constraints, besides whatever you may have created programmatically or created in Interface Builder. And I have noticed some iOS generated constraints can disappear in different devices and orientations, as the iOS implementation that applies and removes such constraints is a black box.

UIView issue with iPad Air 2. Touches go through, any ideas why this might be?

So I have a custom UIView class (which I call UIStageView) that emulates the look of a prompt in which the background is darkened and its view brought to center (code below). Now, it works perfectly when run on any iPad EXCEPT iPad airs.
For some reason, touch immediately goes through the UIStageView and into its parent view. Any reason why this might be? I'm running the project on iOS 8.1 and even when I revert back to 7.1 the bug happens. Note that this problem only happens on iPad Airs (physical and emulator). When run on iPads 1-4, it works.
// UIStageView
- (id)initWithFrame:(CGRect)frame withTarget:(UIView *)target {
// Init Background
CGFloat screenWidth = target.frame.size.width;
CGFloat screenHeight = target.frame.size.height;
CGRect rFrame = CGRectMake(0, 10, screenWidth, screenHeight);
if (self = [super initWithFrame:rFrame]) {
[self initSubWithFrame:frame withTarget:(UIView *)target];
[self initExtension];
self.userInteractionEnabled = true;
NSLog(#"StageView inited! :)");
}
return self;
}
- (void)initSubWithFrame:(CGRect)frame withTarget:(UIView *)target {
[self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.8]];
_properFrame = frame;
_entranceFrame = CGRectMake(frame.origin.x, frame.origin.y-frame.size.height/2, frame.size.width, frame.size.height);
_babyView = [[UIView alloc] initWithFrame:_entranceFrame];
[_babyView setBackgroundColor:[UIColor whiteColor]];
_babyView.layer.cornerRadius = 15;
_babyView.layer.masksToBounds = YES;
[self addSubview:_babyView];
_target = target;
_indent = 5;
}
Basically, the way my code works is that the UIStageView itself becomes relegated to serving as a background while the _babyView becomes the main view and is what gets interacted with by the user.
I also have a method set up that removes the UIStageView from its parent view when tapped.
This works perfectly on any iPad I've tried (physical and emulator) EXCEPT iPad Airs. Any ideas? :\
Fixed it! As it turns out, declaring #property (nonatomic)float alpha was causing UIView to malfunction. I noticed my UIView wouldn't accept touches at all on either iPad Air or iPad Retina when I didn't explicitly set it (i.e. _alpha = .5) and it would fail only on iPad Air when I did set it (i.e. _alpha = .5).
EDIT:
Just found out that alpha really is a reserved word and I just never noticed. My bad :\

xcode: ios8, rotate on single view of the app

I have an app that I have set to only run on portrait mode only.
But I have a page view where I am showing a photo but wants to enable it to auto rotate with the device. I tried to put these codes but its not working
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate {
return YES;
}
Can someone please advise what's needed to do now?
You have to set the point of rotation on your imageview
UIImageView *yourImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"logo.png"]];
yourImageView.center = CGPointMake(100.0, 100.0);
yourImageView.transform = CGAffineTransformMakeRotation(M_PI_2);

Resources