为什么iOS头文件中列出了私有属性?

为什么iOS头文件中列出了私有属性?,ios,header,private,Ios,Header,Private,我正在研究如何在iOS6中使用uipangestrerecognizer,并研究了头文件uipangestrerecognizer.h的一部分: NS_CLASS_AVAILABLE_IOS(3_2) @interface UIPanGestureRecognizer : UIGestureRecognizer { @package CGPoint _firstScreenLocation; CGPoint _lastScreenLocat

我正在研究如何在iOS6中使用uipangestrerecognizer,并研究了头文件uipangestrerecognizer.h的一部分:

NS_CLASS_AVAILABLE_IOS(3_2) @interface UIPanGestureRecognizer : UIGestureRecognizer {
    @package
    CGPoint         _firstScreenLocation;
    CGPoint         _lastScreenLocation;
    NSTimeInterval  _lastTouchTime;
    id              _velocitySample;
    id              _previousVelocitySample;
    NSMutableArray  *_touches;
    NSUInteger      _lastTouchCount;
    NSUInteger      _minimumNumberOfTouches;
    NSUInteger      _maximumNumberOfTouches;
    CGFloat         _hysteresis;
    CGPoint         _lastUnadjustedScreenLocation;
    unsigned int    _failsPastMaxTouches:1;
    unsigned int    _canPanHorizontally:1;
    unsigned int    _canPanVertically:1;
    unsigned int    _ignoresStationaryTouches:1;
}

@property (nonatomic)          NSUInteger minimumNumberOfTouches;   // default is 1. the minimum number of touches required to match
@property (nonatomic)          NSUInteger maximumNumberOfTouches;   // default is UINT_MAX. the maximum number of touches that can be down

- (CGPoint)translationInView:(UIView *)view;                        // translation in the coordinate system of the specified view
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view;

- (CGPoint)velocityInView:(UIView *)view;                           // velocity of the pan in pixels/second in the coordinate system of the specified view

@end
我想和你一起做点什么

CGPoint         _firstScreenLocation;
这不是@属性,所以是私有的

我当时的问题是:为什么我们能够看到这些私人物品?既然它们是“私人”的,如何使用它们

我想可能是为了防止我们想对对象进行子类化,所以我尝试如下操作:

#import <UIKit/UIGestureRecognizerSubclass.h>

@interface MyPanGesture : UIPanGestureRecognizer

- (CGPoint) firstLocation;

@end

@implementation MyPanGesture

- (CGPoint) firstLocation
{
    return self->_firstScreenLocation;
}

@end
#导入
@接口mypangestrue:UIpangestruerecognizer
-(CGPoint)第一位置;
@结束
@实现MyPanGesture
-(CGPoint)第一位置
{
返回self->\u firstScreenLocation;
}
@结束
但由于链接错误,无法生成:

架构armv7s的未定义符号: “_OBJC_IVAR_$_UIPangestureRecognitor._firstScreenLocation”,引用自: -[MyPanGesture firstLocation]在手势中。o ld:找不到架构armv7s的符号 叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用)

有人能帮助这个困惑的人吗?

看看。 该指令意味着只有属于同一映像的类才能访问该变量;这意味着只有UIKit类可以访问_firstScreenLocation

看一看。
该指令意味着只有属于同一映像的类才能访问该变量;这意味着只有UIKit类可以访问_firstScreenLocation

它失败的原因正是您声明的,它是私有的(实际上是包,这有点不同,但它对您是私有的)。您可以看到它们,因为这些实例变量将公开给它自己包的其余部分。该软件包是
UIKit

你做不到

(旁白:公共/私人身份独立于是ivar还是财产)

您应该设置一个,它将在pan发生时调用方法

UIP感测识别器

此类的客户端可以在其动作方法中查询UIPangestureRecognitor对象,以获取手势的当前翻译(TranslationView:)和翻译速度(VelocityView:)。它们可以指定平移和速度值应使用其坐标系的视图。客户端还可以将翻译重置为所需的值


它失败的原因正是您声明的,它是私有的(实际上是包,这有点不同,但它对您是私有的)。您可以看到它们,因为这些实例变量将公开给它自己包的其余部分。该软件包是
UIKit

你做不到

(旁白:公共/私人身份独立于是ivar还是财产)

您应该设置一个,它将在pan发生时调用方法

UIP感测识别器

此类的客户端可以在其动作方法中查询UIPangestureRecognitor对象,以获取手势的当前翻译(TranslationView:)和翻译速度(VelocityView:)。它们可以指定平移和速度值应使用其坐标系的视图。客户端还可以将翻译重置为所需的值


那些不是私人财产。它们是实例变量,并且被标记为在“包”范围内。这些不是私有属性。它们是实例变量,并且被标记为在“包”范围内。