Project encountered, so check the data to write their own demo test.
1Uiscrollview *scrollview =[[Uiscrollview alloc] initWithFrame:self.view.bounds];2Scrollview.backgroundcolor =[Uicolor Whitecolor];3 [Self.view Addsubview:scrollview];4 5 //Source View6UIView *sourceview = [[UIView alloc] Initwithframe:cgrectmake ( -, the, -, +)];7Sourceview.backgroundcolor =[Uicolor Redcolor];8 [ScrollView Addsubview:sourceview];9 Ten //Target View OneUIView *destinationview = [[UIView alloc] Initwithframe:cgrectmake ( -, -, the, -)]; ADestinationview.backgroundcolor =[Uicolor Greencolor]; - [Self.view Addsubview:destinationview]; - theLabel0://Error Conversion - { - //abnormal doubling target x+| source X-target x|*2 target y+| source y-Target y|*2 -CGRect rect =[Sourceview convertRect:sourceView.frame Toview:destinationview]; +NSLog (@"%@", Nsstringfromcgrect (rect)); - + //two correct methods A //label3: [Sourceview.superview convertRect:sourceView.frame Toview:destinationview]; at //Label1: [Sourceview convertRect:sourceView.bounds Toview:destinationview]; - //for Convertrect callers to understand the error, it should be necessary to convert the control's reference view, not itself. - } - - Label1: - { in //the size of the source view to be mapped to the target view to return its size -CGRect rect =[Sourceview convertRect:sourceView.bounds Toview:destinationview]; toNSLog (@"%@", Nsstringfromcgrect (rect)); + } - the Label2: * { $CGRect rect =[Destinationview convertRect:sourceView.bounds Fromview:sourceview];Panax NotoginsengNSLog (@"%@", Nsstringfromcgrect (rect)); - } the + Label3: A { theCGRect rect =[Sourceview.superview convertRect:sourceView.frame Toview:destinationview]; +NSLog (@"%@", Nsstringfromcgrect (rect)); - } $ $Label4://Error Conversion - { - //abnormal doubling target x+| source X-target x|*2 target y+| source y-Target y|*2 theCGRect rect =[Destinationview convertRect:sourceView.frame Fromview:sourceview]; -NSLog (@"%@", Nsstringfromcgrect (rect));Wuyi //two correct methods the //label5: [Destinationview convertRect:sourceView.frame FromView:sourceView.superview]; - //label2: [Destinationview convertRect:sourceView.bounds Fromview:sourceview]; Wu //for Convertrect callers to understand the error, it should be necessary to convert the control's reference view, not itself. - } About $ Label5: - { -CGRect rect =[Destinationview convertRect:sourceView.frame FromView:sourceView.superview]; -NSLog (@"%@", Nsstringfromcgrect (rect)); A } + the /* - -(Cgpoint) Convertpoint: (cgpoint) point Toview: (Nullable UIView *) view; $ -(Cgpoint) Convertpoint: (cgpoint) point Fromview: (Nullable UIView *) view; the -(CGRect) Convertrect: (cgrect) Rect toview: (Nullable UIView *) view; the -(CGRect) Convertrect: (cgrect) Rect fromview: (Nullable UIView *) view; the Summary: the 1. From and to is a corresponding set of functions, proficiency of a can, I am accustomed to using to. - 2. Function: Calculates the [manipulated object] on [source] frame relative to [target]. From: Source to: The target then corresponds to the caller is the from or to the corresponding in 3. The caller should be a reference-system view that needs to convert the control, not itself. the 4. There are not many differences between point and rect. the */
Demo Link: Https://pan.baidu.com/s/1skEi0FV Password: 8SWH
IOS convertRect:view.frame toview:x Abnormal double?