For some reasons I want to set my navigation items' alpha with panGesture.
And my view's height is larger than screen's height, eg screen height is 568 but I set my view's height to 668.
The code I change navigation items:
-(void)hideTopview:(CGFloat) alpha{
alpha = (alpha - 64)/100;
float adjustAlpha;
if (alpha < 0) {
alpha = 0;
}
if (alpha < 0.5) {
self.navigationItem.rightBarButtonItem = self.rightBarItemSmall;
self.navigationItem.titleView = self.naviShopName;
self.naviShopName.frame = CGRectMake(0, 0, 200, 30);
self.naviShopName.alpha =0;
self.naviRightViewSmall.alpha = 0;
adjustAlpha = (alpha)/0.5;
self.naviShopName.alpha =1 - adjustAlpha;
self.naviRightViewSmall.alpha = 1 - adjustAlpha;
}
if(alpha > 0.5){
self.navigationItem.rightBarButtonItem = self.rightBarItemFull;
self.navigationItem.titleView = nil;
if (alpha>1) {
adjustAlpha = 1;
}
else{
adjustAlpha = (alpha - 0.5)/0.5;
}
self.naviRightViewFull.alpha = adjustAlpha;
}
}
Before Run this code, the view frame height is 668, after run this code, it change to 568. I also trying to set frame in the function but not work.
CGRect frame = self.view.frame;
frame.size.height = self.superViewHeight;
self.view.frame = frame;
Related
I have an app which is compiled in Xcode 10 on iOS 13 simulator. In one view there is a "tray" view which shows from the bottom when tapped, in iOS 12 it works perfectly, in iOS 13, the tap is calling the method, but the changes to the frame are not saving - I have included outputs from the debugger in comments so you can see what the outputs of the frame values are;
- (void) userClickActivityTray: (UITapGestureRecognizer *) gestureRecognizer {
if(self.activityTrayShown) {
/*
(lldb) po self.activityTrayContainerView.frame
(origin = (x = 0, y = 792), size = (width = 414, height = 104))
*/
[self hideActivityTray];
} else {
if (!self.activityTrayViewInitialFrameComputed) {
self.activityTrayViewInitialFrameComputed = YES;
self.activityTrayInitialFrame = self.activityTrayContainerView.frame;
}
/*
(lldb) po self.activityTrayContainerView.frame
(origin = (x = 0, y = 638), size = (width = 414, height = 224))
(origin = (x = 0, y = 638), size = (width = 414, height = 224))
(lldb) po self.activityTrayInitialFrame
(origin = (x = 0, y = 792), size = (width = 414, height = 104))
(origin = (x = 0, y = 792), size = (width = 414, height = 104))
(lldb)
*/
[UIView animateWithDuration:0.25 animations:^{
self.activityTrayContainerView.frame = CGRectMake(self.view.bounds.origin.x,
self.bottomView.frame.origin.y - self.activityTrayViewController.maximumHeight,
self.view.bounds.size.width,
self.activityTrayViewController.maximumHeight);
self.activityTrayBackgroundView.alpha = 1.0;
self.bottomView.alpha = self.dotsProgressView.alpha = 0;
} completion:^(BOOL finished) {
self.activityTrayShown = YES;
/*
(lldb) po self.activityTrayContainerView.frame
(origin = (x = 0, y = 557), size = (width = 414, height = 305))
(origin = (x = 0, y = 792), size = (width = 414, height = 104))
*/
}];
}
}
Layout system in iOS 13 is different, we had the same issue and in our case by switching layout from automatic to Translates Mask Into Constraints fixed the issue.
You can use yourview.layer.frame instead of yourview.frame
It worked for me.
I had the same issue when moving to iOS13.
In my case, the sizing constraints were overriding any change I was making to the frame, which was not the case on iOS12.
For my app to work correctly, I had to also update the NSLayoutContraint just before the "animateWithDuration" block, so that the new frame coordinates stay compatible with the layout constraints.
Hope that helps
only set .translatesAutoresizingMaskIntoConstraints 's View to YES, it worked for me.
Hope that helps
Hi i'm trying to add a top and bottom margin to all my PackageCells.
like
what ive tried
%hook PackageCell
-(void)didMoveToWindow {
self.layer.cornerRadius = 15.0f;
self.layer.masksToBounds = true;
%orig;
}
-(CGRect)frame {
CGRect r = %orig;
return CGRectMake(40, 0, r.size.width, r.origin.height+20);
}
-(void)setFrame:(CGRect)frame {
CGRect r = frame;
%orig(CGRectMake(40, 0, r.size.width, r.origin.height+20));
}
%end
All cells get stacked on top of eachother and look weird.
You should set the backgroundColor of the cell to [UIColor clear]
And Change the frames of the contentView instead and make that view round
self.contentView.layer.cornerRadius = 15.0f;
And update the frame for this
self.contentView.frame = CGRectMake(40, 0, self.frame.size.width, self.frame.origin.height+20);
I'm displaying a RTCVideoTrack with RTCEAGLVideoView, and want it to be full screen, but it always deforms.I have tried to use AVMakeRectWithAspectRatioInsideRect method to display this view, there's no distortion but no full screen either, here is my code.
RTCEAGLVideoView *remoteVideoView = [[RTCEAGLVideoView alloc] initWithFrame:self.backView.bounds];
remoteVideoView.contentMode = UIViewContentModeScaleAspectFill;
_remoteVideoView = remoteVideoView;
[remoteVideoView renderFrame:nil];
[remoteVideoTrack addRenderer:remoteVideoView];
remoteVideoView.delegate = self;
self.remoteVideoTrack = remoteVideoTrack;
[self.backView addSubview:remoteVideoView];
when didChangeVideoSize delegate called:
- (void)videoView:(RTCEAGLVideoView*)videoView didChangeVideoSize:(CGSize)size {
if (videoView == _remoteVideoView) {
_remoteVideoSize = size;
}
CGRect bounds = self.view.bounds;
if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) {
// Aspect fill remote video into bounds.
CGRect remoteVideoFrame =
AVMakeRectWithAspectRatioInsideRect(_remoteVideoSize, bounds);
CGFloat scale = 1;
if (remoteVideoFrame.size.width > remoteVideoFrame.size.height) {
// Scale by height.
scale = bounds.size.height / remoteVideoFrame.size.height;
} else {
// Scale by width.
scale = bounds.size.width / remoteVideoFrame.size.width;
}
remoteVideoFrame.size.height *= scale;
remoteVideoFrame.size.width *= scale;
_remoteVideoView.frame = remoteVideoFrame;
_remoteVideoView.center =
CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
} else {
_remoteVideoView.frame = bounds;
}
}
I am wondering if the method of renderFrame can do something helpful, but i can't find how to create a RTCI420Frame property.
You can use RTCMTLVideoView to set contentMode(full screen).
Import:
#import <WebRTC/RTCMTLVideoView.h>
Use this code here:
#if defined(RTC_SUPPORTS_METAL)
RTCMTLVideoView *mtlVideoView = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
mtlVideoView.videoContentMode = UIViewContentModeScaleAspectFill;
#else
//Here you can create RTCEAGLVideoView
I customed a UITabBar. Add a button to center of UITabBar. tabbar have 4 tabbaritems and a button. But when I tap on the third tabbaritem, its position changed to the fourth item's position. Third tabbaritem and fourth item exchange their position.
I set a breakpoint debugging. I found when I taped on third babbaritem tabBar called layoutSubviews(), but when I tap on the other three tabbaritems, tabbar didn't call layoutSubviews(). I don't konw why. Anybody can help me?
I upload the code. add tag to every UITabBarButton. then use tag multiply width. But it has a new problem. the third item become the first item.
Here is the fixed custom UITarbar.
class YNNJTTabBar: UITabBar {
override func awakeFromNib() {
super.awakeFromNib()
self.addSubview(askQuestionButton)
addTagToUITarBarButton()
}
func addTagToUITarBarButton() {
var index = 0
for view in self.subviews {
if view is UIControl && !(view is UIButton) {
view.tag = index
index += (index == 1) ? 2 : 1
}
}
}
override func layoutSubviews() {
super.layoutSubviews()
let width = self.bounds.width / CGFloat(buttonCount)
let height = self.bounds.height
let frame = CGRect(x: 0, y: 0, width: width, height: height)
//set askQuestionButton's frame
let buttonFrame = CGRect(x: 0, y: 0, width: width - 12, height: height - 12)
askQuestionButton.frame = buttonFrame
askQuestionButton.center = CGPoint(x: self.bounds.width * 0.5, y: self.bounds.height * 0.5)
//set 4 item's frame
for view in self.subviews {
if view is UIControl && !(view is UIButton) {
print(view.tag)
view.frame = CGRectOffset(frame, width * CGFloat(view.tag), 0)
}
}
print(self.subviews as NSArray)
}
private let buttonCount = 5
let askQuestionButton: UIButton = {
let tempView = UIButton()
tempView.setBackgroundImage(UIImage(named: "askQuestionbtn"), forState: .Normal)
tempView.setTitle("问", forState: .Normal)
tempView.titleLabel?.font = UIFont.systemFontOfSize(22)
return tempView
}()
}
Here is print information, when app launched
0
1
3
4
(
"<_UITabBarBackgroundView: 0x7fe47bc0d580; frame = (0 0; 320 49); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7fe47bc02740>>",
"<UITabBarButton: 0x7fe47bccb060; frame = (0 0; 64 49); opaque = NO; layer = <CALayer: 0x7fe47bca51f0>>",
"<UITabBarButton: 0x7fe47bccc9e0; frame = (64 0; 64 49); opaque = NO; tag = 1; layer = <CALayer: 0x7fe47bcccf80>>",
"<UITabBarButton: 0x7fe47bccea80; frame = (192 0; 64 49); opaque = NO; tag = 3; layer = <CALayer: 0x7fe47bccf020>>",
"<UITabBarButton: 0x7fe47bcd0ad0; frame = (256 0; 64 49); opaque = NO; tag = 4; layer = <CALayer: 0x7fe47bcd1050>>",
"<UIButton: 0x7fe47bcca690; frame = (134 6; 52 37); opaque = NO; layer = <CALayer: 0x7fe47bca3980>>",
"<UIImageView: 0x7fe47bc22b80; frame = (0 -0.5; 320 0.5); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7fe47bc07b80>>"
)
when I tap on third item
0
1
4
0
(
"<_UITabBarBackgroundView: 0x7fe47bc0d580; frame = (0 0; 320 49); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7fe47bc02740>>",
"<UITabBarButton: 0x7fe47bccb060; frame = (0 0; 64 49); opaque = NO; layer = <CALayer: 0x7fe47bca51f0>>",
"<UITabBarButton: 0x7fe47bccc9e0; frame = (64 0; 64 49); opaque = NO; tag = 1; layer = <CALayer: 0x7fe47bcccf80>>",
"<UITabBarButton: 0x7fe47bcd0ad0; frame = (256 0; 64 49); opaque = NO; tag = 4; layer = <CALayer: 0x7fe47bcd1050>>",
"<UIButton: 0x7fe47bcca690; frame = (134 6; 52 37); opaque = NO; layer = <CALayer: 0x7fe47bca3980>>",
"<UIImageView: 0x7fe47bc22b80; frame = (0 -0.5; 320 0.5); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7fe47bc07b80>>",
"<UITabBarButton: 0x7fe47bcd0150; frame = (0 0; 64 49); opaque = NO; layer = <CALayer: 0x7fe47bcb8f10>>"
)
If 'self.subviews' returning items not in correct order,
Set tag for each tab item.
The tag values will be 0(for search), 1 (for contact), 3 and 4 (for settings)
And inside the for loop change like:
if view is UIControl && !(view is UIButton) {
view.frame = CGRectOffset(frame, view.tag * width, 0)
}
I think your code here basically won't cause the problem, so I guess the cause comes from other code, so checkout other code or show us more code to help you. just like:
button creation code
button click action code
and so on
I am trying to centre an imgView inside a scrollView so that when I zoom in, it will remain centred properly (like the photos app).
When the screen first loads, it is centred ok. When I pinch and start to zoom, the position adjusts itself so the image is no longer centred. See before and after pinch/zoom photos.
The red is the background color of the scrollview.
Here is the code I am using to create the imgView and Center it within the scroll view.
(MonoTouch, but should translate over to Obj-C easy)
private void LoadPageContent(int page)
{
//TODO: Code to put here to load image or whateer you want to display on this panel/page
//Each page will have it's own scrollview for scrolling and zooming that image on the page
var panelScrollView = new UIScrollView();
_panels.Add (panelScrollView);
panelScrollView.CanCancelContentTouches=false;
panelScrollView.ClipsToBounds = true;
panelScrollView.MinimumZoomScale = 1f;
panelScrollView.MaximumZoomScale = 50.0f;
panelScrollView.MultipleTouchEnabled = true;
panelScrollView.ScrollEnabled = true;
panelScrollView.UserInteractionEnabled=true;
var ui = new UIImage (_assetImages[page], 1.0f, UIImageOrientation.Up);
UIImageView imgView = new UIImageView(ui);
panelScrollView.Frame = new RectangleF(scrollView.Frame.Width * (_numberOfPanels - 1),
0,
_pageWidthPortrait,
scrollView.Frame.Height);
panelScrollView.BackgroundColor = UIColor.Red;
//scale down image to get proper fitted imgview dimensions
float nPercentW = (panelScrollView.Frame.Width / (float)imgView.Image.Size.Width);
float nPercentH = (panelScrollView.Frame.Height / (float)imgView.Image.Size.Height);
float newPercent;
if (nPercentH >= nPercentW)
{
//wider than it is tall
newPercent = nPercentW;
}
else{
//taller than it is wide..
newPercent = nPercentH;
}
int newWidth1 = Convert.ToInt32(imgView.Image.Size.Width * newPercent);
int newHeight = Convert.ToInt32(imgView.Image.Size.Height * newPercent);
panelScrollView.ViewForZoomingInScrollView += (UIScrollView sv) => {
return imgView;
};
imgView.Frame = new RectangleF(0,0,newWidth1, newHeight);
imgView.Center = new PointF(panelScrollView.Frame.Width /2,
(panelScrollView.Frame.Height/2));
//ScaleToFill and ScaleAspect fit - i used scaleaspectfit and it had the same problem
//I tried scaletofill but resizing the imgView to fit the proper view dimensions so it is like an aspect fit, but same problem
imgView.ContentMode=UIViewContentMode.ScaleToFill;//ScaleAspectFit;
imgView.UserInteractionEnabled=true;
panelScrollView.ContentSize = imgView.Image.Size;
panelScrollView.DidZoom += (object sender, EventArgs e) => {
};
panelScrollView.AddSubview(imgView);
scrollView.AddSubview(panelScrollView);
}
This is working fine for me
- (void)centerScrollViewContents {
CGSize boundsSize = ScrollView.bounds.size;
CGRect contentsFrame = ImageView.frame;
if (contentsFrame.size.width < boundsSize.width) {
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
} else {
contentsFrame.origin.x = 0.0f;
}
if (contentsFrame.size.height < boundsSize.height) {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
} else {
contentsFrame.origin.y = 0.0f;
}
ImageView.frame = contentsFrame;
}
You have to call this method in
- (void)scrollViewDidZoom:(UIScrollView *)scrollView