Unable to add QLPreviewController as childViewController iOS10 - ios

I am trying to add QLPreviewController as childViewController. However I got no success on iOS10. I have checked this link.. No success. Here is my code:
let previewController:QLPreviewController = QLPreviewController()
previewController.dataSource = self
previewController.currentPreviewItemIndex = 0
self.addChildViewController(previewController)
self.view.addSubview(previewController.view)
previewController.view.didMoveToSuperview()
This code block works on the iOS9. Any help will be appreciated.

In this case, the view you are has a zero rect. That is why it is not visible. You can solve it in two different ways:
- Using auto layout.
- Setting to frame and the autoresizing mask:
previewController.view.frame = self.view.frame;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Related

Media Items in JSQMessageViewController's Collection cells are not showing in IOS 14

I am using JSQMessageViewController and I am facing the issue (only in ios14) that i cant see media items like Images, Video and Audio in device though these views are generating debug view hierarchy. See below attached image:-
debug view hierarchy screenshot:
here is the description of UIImage inside collection view cell:
<UIImageView: 0x7fe7d6d95b30; frame = (20 8; 177 131); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x600001ce4ec0>>
here is the screenshot attached of screen:
You can see the view has generated space for image, but its not showing up!
Is anyone facing this issue? how can i solve this problem. This issue is occurring in iOS 14, it works perfectly in iOS 13.
You need to overwrite in JSQMessagesMediaViewBubbleImageMasker.m
method - (void)jsq_maskView:(UIView *)view withImage:(UIImage *)image and change line:
view.layer.mask = imageViewMask.layer;
to be
view.maskView = imageViewMask;
I suggest you to use category for that. For me that was solution.
I would like to suggest to change like as follows along with the Vladimir answer for backward compatibility:
if (#available(iOS 14.0, *)) {
view.maskView = imageViewMask;
} else {
view.layer.mask = imageViewMask.layer;
}

get image view exact frame after transformed/rotation apply in landscape mode

I am working on an app where I have just assign the transformation to image view when device rotated in landscape mode. Now I want exact frame of that image view after transformation applied to it. I have tried with this example: Find Frame Coordinates After UIView Transform is Applied (CGAffineTransform) but not succeeded. Code I have used:
UIView *Newview = [[UIView alloc] initWithFrame:_FullImageView.frame];
_FullImageView.transform=CGAffineTransformMakeRotation(-M_PI_2);
_FullImageView.frame = CGRectMake(Newview.frame.origin.x, Newview.frame.origin.y,Newview.frame.size.width,Newview.frame.size.height);
_FullImageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
If anybody have any suggestion then please let me know. It would be very appreciated. Thanks.
Please check the following code. Hope you need the same.
UIView*Newview = [[UIView alloc] initWithFrame:_FullImageView.frame];
_FullImageView.transform=CGAffineTransformMakeRotation(-M_PI_2);
CGRect rect = _FullImageView.frame;
Check rect frame , it gives you the frame after transform.

Google Maps iOS SDK - Add GMSPanoramaView in a SubView

I'm trying to add a GMSPanoramaView to a SubView.
Here is the code I'm working on :
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectZero];
panoView_.delegate = self;
self.view = panoView_;
[panoView_ moveNearCoordinate:CLLocationCoordinate2DMake(emplLatitude, emplLongitude)];
This code renders the panorama on fullscreen mode.
If I try this, nothing happens :
self.myView = panoView_;
Where myView outlet is set in my storyboard.
This stack is a possible duplicate of this one which never got answered.
Help appreciated :)
Works when panoView_ is NOT inited with CGRectZero
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectMake(200, 200, 400, 400)];
self.myView.frame = panoView_.frame;
[self.myView addSubview:panoView_];
I have had similar issues in the past.
Usually by setting the frame of the panoView_ to be that of the subview, it has worked for me:
self.myView.frame = panoView_.frame;
If that doesn't work, try checking to see if the panoView_ is in the subview's view hierarchy:
NSLog(#"%#", self.myView.subviews);
You can then try adding it as a subview if needed:
[self.myView addSubview:panoView_];

Map rotation horribly slow on ios8

I got the following code in a VC in an old project (no storyboard, pure code) :
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[MKMapView alloc] initWithFrame:CGRectInset(self.view.frame, 10, 10) ];
[self.view addSubview:self.mapView];
self.view.backgroundColor = [UIColor redColor];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.view.translatesAutoresizingMaskIntoConstraints = NO; // <--- this line
}
If I comment the last line, a rotation from portrait to landscape or the other way is about 3 seconds under ios8 !! Also, occasionally at random times Unable to allocate render buffer storage! errors appear.
If I don't comment it, it's almost instantaneous (0.7seconds).
It seems it is only related to mapviews, the other views/VCs rotate just fine.
Under ios7 the rotation is fast in any case with that line commented or not.
Why ? And why is only the mapview affected ?
Edit: It seems clearly the autoresizingmask is wrong. If in viewDidLoad I set its value to none and manually change the frame in willRotate, it works fast.
I had the same problem when the application came back from the background. It froze a few seconds and then it worked again. I used a .xib file without Autolayout.
When I updated the .xib file and added the Autolayout option the problem was gone. I came up with this idea because you wrote that autoresizing was the problem in your solution.

UIImageView shadow not working

Am not sure where an wrong. I have an UIImageView in Storyboard, which am connecting with an IBOutlet to the code. I want to add a shadow (during runtime) to the UIImageView. And am using this code snippet for that (got this help from a stackoverflow post) :
-(void) awakeFromNib {
self.imageViewTopBar.layer.shadowColor = [UIColor blueColor].CGColor;
self.imageViewTopBar.layer.shadowOffset = CGSizeMake(0, 5);
self.imageViewTopBar.layer.shadowOpacity = 1.0;
self.imageViewTopBar.layer.shadowRadius = 3.0;
//self.imageViewTopBar.layer.masksToBounds = YES;
//self.imageViewTopBar.clipsToBounds = NO;
self.imageViewTopBar.layer.shouldRasterize = YES;
}
but it simply doesn't work. Any help please? I don't see any reason why it shouldn't work.
My environment : XCode 4.5.2, iOS 5, iPhone 4
You should use -viewDidLoad to do this, check out this post: Accessing View in awakeFromNib?
Try putting it into viewDidLoad. I assume you've included the quartzcore framework. I think it would throw compiler error if not...
Do you have checked, in the xib, clipToBounds to YES?
If YES you should uncheck the clipToBounds and reorganize your view hierarchy.
Normally when i have an imageView with a shadow i use this hierarchy
(aImageView) ClipToBounds=YES
|
|
(aView) Shadow setted here
|
|
(Superview)
aView has the same frame size of the aImageView

Resources