developer tip

다른 모든보기 앞에 하위보기 가져 오기

copycodes 2020. 12. 2. 21:30
반응형

다른 모든보기 앞에 하위보기 가져 오기


현재 내 앱에 광고 제공 업체를 통합하는 중입니다. 광고가 표시되지만 완전히 실패했을 때 광고 앞에 페이딩 메시지를 표시하고 싶습니다.

현재 뷰에 하위 뷰를 추가하고이를 사용하여 앞으로 가져 오려고하는 기능을 만들었습니다.

[self.view bringSubviewToFront:mySubview]

이 함수는 광고가로드되었다는 알림 (광고 제공 업체의 SDK에서 가져온 알림)에 대해 실행됩니다. 그러나 내 하위보기가 광고 앞에 끝나지 않습니다. 광고 제공 업체가 고의로 어렵게 만드는 일이라고 생각하지만 상관없이하고 싶습니다. 나는 현재 이것이 허용 될 수 있는지 제공자와 논의하고 있습니다. 그러나 당분간 나는 그것이 가능 할지를 알고 싶습니다.

어쨌든 내 하위보기를 맨 위보기로 강제하여 아무것도 방해하지 않도록 할 수 있습니까?


광고 제공 업체의보기가 추가되지 않고 self.view다음과 같은 항목에 추가되면 [UIApplication sharedApplication].keyWindow어떻게됩니까?

다음과 같이 시도하십시오.

[[UIApplication sharedApplication].keyWindow addSubview:yourSubview]

또는

[[UIApplication sharedApplication].keyWindow bringSubviewToFront:yourSubview]

이 시도:

self.view.layer.zPosition = 1;

Jere의 답변의 Swift 2 버전 :

UIApplication.sharedApplication().keyWindow!.bringSubviewToFront(YourViewHere)

스위프트 3 :

UIApplication.shared.keyWindow!.bringSubview(toFront: YourViewHere)

스위프트 4 :

UIApplication.shared.keyWindow!.bringSubviewToFront(YourViewHere)

누군가가 10 초를 절약하기를 바랍니다! ;)


나는 이것을 한 번 필요했습니다. 사용자 지정 UIView클래스를 만들었습니다 - AlwaysOnTopView.

@interface AlwaysOnTopView : UIView
@end

@implementation AlwaysOnTopView

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (object == self.superview && [keyPath isEqual:@"subviews.@count"]) {
        [self.superview bringSubviewToFront:self];
    }

    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}

- (void)willMoveToSuperview:(UIView *)newSuperview {
    if (self.superview) {
        [self.superview removeObserver:self forKeyPath:@"subviews.@count"];
    }

    [super willMoveToSuperview:newSuperview];
}

- (void)didMoveToSuperview {
    [super didMoveToSuperview];

    if (self.superview) {
        [self.superview addObserver:self forKeyPath:@"subviews.@count" options:0 context:nil];
    }
}

@end

당신의 견해가이 클래스를 확장하도록하십시오. 물론 이것은 하위 뷰가 모든 형제 뷰 위에 있음을 보장합니다.


내가 경험 한 한 zposition이 가장 좋은 방법입니다.

self.view.layer.zPosition = 1;


C #에서는 View.BringSubviewToFront (childView); YourView.Layer.ZPosition = 1; 둘 다 작동합니다.


에서 스위프트 4.2

UIApplication.shared.keyWindow!.bringSubviewToFront(yourView)

출처 : https://developer.apple.com/documentation/uikit/uiview/1622541-bringsubviewtofront#declarations


xamarin ios : this.InsertSubview (subview_youwant_beback, 0);

참고URL : https://stackoverflow.com/questions/13182482/bringing-a-subview-to-be-in-front-of-all-other-views

반응형