gpt4 book ai didi

ios - 为什么私有(private)属性会列在 iOS 头文件中?

转载 作者:行者123 更新时间:2023-11-29 13:11:14 25 4
gpt4 key购买 nike

我正在研究如何在 iOS6 中使用 UIPanGestureRecognizer 做一些事情,并查看了头文件 UIPanGestureRecognizer.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;

这不是@property,所​​以它是私有(private)的。

然后我的问题是:为什么我们能够看到这些私有(private)项目?鉴于它们是“私有(private)的”,如何使用它们?

我想也许是为了万一我们想要子类化这个对象,所以我试着这样做:

#import <UIKit/UIGestureRecognizerSubclass.h>

@interface MyPanGesture : UIPanGestureRecognizer

- (CGPoint) firstLocation;

@end

@implementation MyPanGesture

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

@end

但是由于链接错误而无法构建:

架构 armv7s 的 undefined symbol : “_OBJC_IVAR_$_UIPanGestureRecognizer._firstScreenLocation”,引用自: -Gesture.o 中的 [MyPanGesture firstLocation]ld:未找到体系结构 armv7s 的符号clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

谁能帮助这个困惑的人?

最佳答案

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

关于ios - 为什么私有(private)属性会列在 iOS 头文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17324923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com